Error: Main method not found in class ServiceProvider, please
define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend
javafx.application.Application
This is the error im getting while executing the following code
Can you modify the error
import java.net.*;
import java.io.*;
public class ServiceProvider extends Thread
{
//initialize socket and input stream
private Socket socket = null;
private ServerSocket server = null;
private DataInputStream in = null;
private DataOutputStream out = null;
private int Port;
// constructor with port
public ServiceProvider(int port)
{
// starts server and waits for a connection
Port = port;
}
public void run()
{
try {
server = new ServerSocket(Port);
socket = server.accept();
System.out.println("Port " + Port + "New Service Request");
// takes input from the client socket
in = new DataInputStream(new
BufferedInputStream(socket.getInputStream()));
out = new DataOutputStream(socket.getOutputStream());
String line = "";
// reads message from client.
while (!line.equals("Close")) {
try {
line = in.readUTF();
String tmp = "can you provide this service?";
if(line.equals(tmp)) {
line = "Yes";
out.writeUTF(line);
}
}
catch(IOException i) {
System.out.println(i);
}
}
// close connection
socket.close();
in.close();
}
catch (Exception e) {
// Throwing an exception
System.out.println ("Exception is caught");
}
}
}
import java.net.*; import java.io.*; public class ServiceProvider extends Thread { //initialize socket and input stream private Socket socket = null; private ServerSocket server = null; private DataInputStream in = null; private DataOutputStream out = null; private int Port; // constructor with port public ServiceProvider(int port) { // starts server and waits for a connection Port = port; } public void run() { try { System.out.println("Listening on port " + Port); server = new ServerSocket(Port); socket = server.accept(); System.out.println("Port " + Port + "New Service Request"); // takes input from the client socket in = new DataInputStream(new BufferedInputStream(socket.getInputStream())); out = new DataOutputStream(socket.getOutputStream()); String line = ""; // reads message from client. while (!line.equals("Close")) { try { line = in.readUTF(); String tmp = "can you provide this service?"; if (line.equals(tmp)) { line = "Yes"; out.writeUTF(line); } } catch (IOException i) { System.out.println(i); } } // close connection socket.close(); in.close(); } catch (Exception e) { // Throwing an exception System.out.println("Exception is caught"); } } public static void main(String[] args) throws InterruptedException { ServiceProvider provider = new ServiceProvider(32412); provider.start(); provider.join(); } }
Error: Main method not found in class ServiceProvider, please define the main method as: public static...
I need help with my IM (instant messaging) java program, I created the Server, Client, and Message class. I somehow can't get both the server and client to message to each other. I am at a roadblock. Here is the question below. Create an IM (instant messaging) java program so that client and server communicate via serialized objects (e.g. of type Message). Each Message object encapsulates the name of the sender and the response typed by the sender. You may...
Using java socket programming rewrite the following program to handle multiple clients simultaneously (multi threaded programming) import java.io.*; import java.net.*; public class WelcomeClient { public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println( "Usage: java EchoClient <host name> <port number>"); System.exit(1); } String hostName = args[0]; int portNumber = Integer.parseInt(args[1]); try ( Socket kkSocket = new Socket(hostName, portNumber); PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true); BufferedReader in = new BufferedReader( new InputStreamReader(kkSocket.getInputStream())); ) { BufferedReader...
Why am I getting "java.net.BindException: Address already in use: NET_Bind" error? My code is below: public ServerSocket server = null; public static void run() throws FileNotFoundException{ PrintWriter logFile = new PrintWriter("C:OutFile.log.txt"); var date = new java.util.Date(); var nDate = date.toString(); try { ServerSocket ss = new ServerSocket(1234); Socket s = ss.accept(); //log connection time logFile.printf("Got a Connection: ",...
I have to modify a server program and chat program to work as the following instructions but I am completely clueless as to where to start. I'd appreciate any help on how to atleast get started. This must be done in java. Diffie-Hellman Two parties use a key agreement protocol to generate identical secret keys for encryption without ever having to transmit the secret key. The protocol works by both parties agreeing on a set of values (a) and (q)....
The DictionaryClient program featured in the class lecture also used the try-catch when creating a socket. Socket are auto-closeable and thus can use a try-with-resources instead. Edit the dictionary program to use try-with-resources instead. package MySockets; import java.net.*; import java.io.*; public class DictionaryClient { private static final String SERVER = "dict.org"; private static final int PORT = 2628; private static final int TIMEOUT = 15000; public static void main(String[] args) { Socket ...
My client java a simple client program java .net import java.io*i public class MyClient (public static void main(String args() thrown IO Exception (part I: initialize rocket and stream BufferedReader inFromUser - new BufferedReader(new inputStreamReader(System in)); Socket clientSocket - new Socket(___. ___); DataOutputStream oldToServer - new DataOutputStream(clientSocket.getOutputStrea, ())); part 2: interact with server
Q7 The following Client side Java code can send a message to the server side via UDP socket. The client side Java code and the server side Java code are running in two different hosts respectively. The server side host name is “MyFileServer”. The server side receives the message and converts all the letters in the message received to uppercase, then sends the modified message back to the client side. Please read the code carefully, and fill out the blanks...
The following Client side Java code can send a message to the server side via UDP socket. The client side Java code and the server side Java code are running in two different hosts respectively. The server side host name is “MyFileServer”. The server side receives the message and converts all the letters in the message received to uppercase, then sends the modified message back to the client side. Please read the code carefully, and fill out the blanks with...
In java write a simple 1-room chat server that is compatible with the given client code. 9 public class Client private static String addr; private static int port; private static String username; 14 private static iter> currenthriter new AtomicReference>(null); public static void main(String[] args) throws Exception [ addr -args[]; port Integer.parseInt (args[1]); username-args[21 Thread keyboardHandler new Thread(Main: handlekeyboardInput); 18 19 while (true) [ try (Socket socket -new Socket (addr, port) println(" CONNECTED!; Printwriter writer new Printwriter(socket.getoutputStreamO); writer.println(username); writer.flush); currenthriter.set(writer); BufferedReader...