multithreading - Java Multiple threads for just 2 computers, how to do it in main -


i'm trying @ least 2 computers connect server, how start second thread?

public static void main(string[] args) throws interruptedexception {     // create server waits client request connection.   while(true){     filesharedserver server = new filesharedserver();     thread thread = new thread(server);     thread.start(); }    } 

this refuses connection

you need wait on serversocket.accept() method on incoming connections in server, , after receiving 1 start thread serve it, server socket stay same, waiting next connection in loop.

while (true) {     socket connection = serversocket.accept();     new therad() {          public void run() {               serveconnection(connection);          }     }.start(); } 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -