Hi everyone,
I am writing a TCP/IP server and a TCP/IP client by java. I can open the connection between server and client; and; I can send data from client to server, however, if i shut my client, my server program is also stopped because of Exception, and i have to run again my server.
I want my server can keep working and listen for other clients after I shut current work client, how should i do ? I am newbie in Java.
Thank in advance,
Here is the code i use to connect server and client:
Socket client = null;
ServerSocket server = null;
public MyServerSocket(int port) throws IOException {
server = new ServerSocket(port);
listen();
}
private void listen(){
try {
System.out.println("Server is waiting for clients...");
client = this.server.accept();
String clientAddress = client.getInetAddress().getHostAddress();
System.out.println("One client has connected to the Command Server:"+ clientAddress);
_hasConnection = 1;
}
catch (IOException e)
{
System.out.println(" Client disconnected........");
System.out.println("=================================");
_hasConnection = 0;
// client = this.server.accept();
}
}