Created
February 25, 2015 08:59
-
-
Save kneradovsky/1bf5e7ca1620b3de1462 to your computer and use it in GitHub Desktop.
Simple java listener for connection check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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