int port = 2345;
ServerSocket ss = new ServerSocket(port);
while (true) {
try {
Socket s = ss.accept();
String response = "Hello " + s.getInetAddress() + " on port "
+ s.getPort() + "\r\n";
response += "This is " + s.getLocalAddress() + " on port "
+ s.getLocalPort() + "\r\n";
OutputStream out = s.getOutputStream();
out.write(response.getBytes("US-ASCII"));
out.flush();
s.close();
}
catch (IOException ex) {
// This is an error on one connection. Maybe the client crashed.
// Maybe it broke the connection prematurely. Whatever happened,
// itâ