java - Accept ServerSocket connection for multiple port -
buyersocket = new serversocket(buyer_port); sellersocket = new serversocket(seller_port); socket clientsocket = null; while (true) { clientsocket = sellersocket.accept(); multiserverthread x = new multiserverthread(clientsocket, dat); x.start(); clientsocket = buyersocket.accept(); multiserverthread y = new multiserverthread(clientsocket, dat); y.start(); }
in block of code, waits sellersocket connect first before accepting buyersocket. suggest way accept whichever come first?
as description of accept() - listens connection made socket , accepts it. method blocks until connection made. should use method instead of accept() if want accept connection multiple ports?
the way use multithreading, because accept() method blocks until connection comes in.
Comments
Post a Comment