Results 1 to 2 of 2
Thread: Server socket won't wait
- 03-16-2012, 10:46 AM #1
Server socket won't wait
Hello. Im trying to make application which have server and to the server can connect many clients. So I just started doing it and I have problem. When I run my server it waits until client connects to server, so if I run client and server got connection, then they send each other a message and disconnecting both. Client can disconnect, I do not care about it now. Now I want to fix server. And I think that I must to tell server that he waits for my command to disconnect because now he disconnects without my command. Here is my server code:
Maybe I must to make it somehow that it disconnects on application close? Or do you have any other suggestions?Java Code:ServerSocket myServerSocket = new ServerSocket(9999); System.out.println("Server is waiting for an incoming connection on host=" + InetAddress.getLocalHost().getCanonicalHostName() + " port=" + myServerSocket.getLocalPort()); Socket skt = myServerSocket.accept(); BufferedReader myInput = new BufferedReader(new InputStreamReader(skt.getInputStream())); PrintStream myOutput = new PrintStream(skt.getOutputStream()); String buf = myInput.readLine(); if (buf != null) { System.out.println("Server read: [" + buf + "]"); myOutput.print("got it"); } //SERVER GOT MESSAGE FROM CLIENT //AND CLOSE THE CONNECTION skt.close(); System.out.println("Server is exiting!");Last edited by Daslee; 03-16-2012 at 10:58 AM.
- 03-16-2012, 12:52 PM #2
Similar Threads
-
non-blocking SSL socket server
By e_scape in forum NetworkingReplies: 0Last Post: 04-12-2011, 05:18 PM -
events on a server socket
By newbiejava in forum New To JavaReplies: 13Last Post: 08-03-2010, 08:24 AM -
Server Socket
By Moncleared in forum New To JavaReplies: 1Last Post: 09-05-2009, 06:08 AM -
how to make server Wait for clients further requests after establishing connection
By nadia in forum NetworkingReplies: 4Last Post: 02-02-2009, 04:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks