multithreading - Java making Proxy Socket multithreaded -


i've built java proxy , works allows 1 client. know need multithreading why have done opens new threads can't work reason...

this proxy class:

public class proxy {      private static serversocket server;     private static int port = 9339;     private static string originalhost = "game.boombeachgame.com";      public static void main(string[] args) throws filenotfoundexception {         system.out.println("info: proxy started");         new thread(new runnable() {              @override             public void run() {                 proxy.startthread();             }          }).start();     }      public static void startthread() {         try {             server = new serversocket(port);             socket clientsocket = server.accept();             new thread(new server(originalhost)).start();             new thread(new client(clientsocket)).start();         } catch (exception e) {             system.out.println(e);         }     }   } 

what need 1 thread running loop checks server socket new connections calling accept() method on serversocket. each connection, need spawn thread handle connection.

what code check server socket new connection, calling accept(), once. correctly spawn off client thread handle connection. however, don't ever call accept() again. why code works, 1 client. spawn off thread "server" object; i'm not sure how fits in.

what need change run "server.accept()" statement , associated thread spawning in loop. need make sure handle threading correctly different connections don't end using each others' data. may require hooking "server" objects , "client" objects in appropriate way.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -