Well I wrote single threaded server and then I followed a tutorial on how to make something multithreaded but to me it seems like I am just calling stuff through a lot of different methods and has not done anything to help.
heres my code:
package server; import java.net.*; import java.io.*; import server.writeFiles.Writer; public class Server implements Runnable { static int port = 5555; static ServerSocket server; static Socket client; static DataInputStream in; public static String message1; public static String message2; public static void main(String[] args) throws IOException { Server s = new Server(); s.run(); } @Override public void run() { try { while (true) { try { startServer(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Thread.sleep(1000L); } } catch (InterruptedException iex) { } } public void startServer() throws IOException { server = new ServerSocket(port); System.out.println("Starting server on port " + port); while (true) { client = server.accept(); System.out.println("Connection"); in = new DataInputStream(client.getInputStream()); message1 = in.readUTF(); System.out.println("Recived:" + message1); message2 = in.readUTF(); System.out.println("Recived:" + message2); Writer.writeFile(); } } }
So my question is. Is this mutlithreaded? Can it handle multiple connections at once?