try {
ServerSocket ss = new ServerSocket(port);
while (true) {
try {
Socket s = ss.accept();
Writer out = new OutputStreamWriter(s.getOutputStream());
out = new BufferedWriter(out);
out.write("Hello " + s.getInetAddress() + " on port "
+ s.getPort() + "\r\n");
out.write("This is " + s.getLocalAddress() + " on port "
+ s.getLocalPort() + "\r\n");
out.flush();
s.close();
}
catch (IOException ex) {
// skip this connection; continue with the next
}
}
}
catch (IOException ex) {
System.err.println(ex);
}