Skip to content

Instantly share code, notes, and snippets.

@kneradovsky
Created February 25, 2015 08:59
Show Gist options
  • Save kneradovsky/1bf5e7ca1620b3de1462 to your computer and use it in GitHub Desktop.
Save kneradovsky/1bf5e7ca1620b3de1462 to your computer and use it in GitHub Desktop.
Simple java listener for connection check
import java.net.*;
import java.io.*;
public class TcpServer {
public static void main(String[] args) throws IOException {
if(args.length<1) {
System.out.println("Usage: program pornum");
return;
}
int port = Integer.parseInt(args[0]);
System.out.println("Listenting on port: "+port);
ServerSocket tcpsock = new ServerSocket(port);
while(true) {
try {
Socket connection = tcpsock.accept();
System.out.println("Connection from: "+connection.getInetAddress().getHostAddress()+":"+connection.getPort());
connection.close();
} catch(Throwable t) {
t.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment