Saturday 15 January 2011

java - program freezes when listening for client through sockets -


I am trying to create a server socket to listen to a client input stream, but when I start_listening Execute () method, my program is stuck. I also tried to remove the loop, but I still have the same problem. I think this customer is waiting for the conversation. Is listening to the program an alternative way, while the program is also working? public static zero start_listening () {listenener = new serverSocket (9090); While (true) {socket socket = listener.accept (); Object InputStream = New Object InputStream (socket.getInputStream ()); Us = (user) in.readObject (); }}

When using socket technology, accept () blocks the execution of existing threads until a client is connected to the listening socket. This is a defined behavior: "The method blocks [ acceptance] ] until a connection is made." Running the server in endless loop can be okay.

So, you can take a look at this to run the whole thing. Within the run () method connection handler , you will be related to your user object.

No comments:

Post a Comment