Guest User

Untitled

a guest
Apr 16th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class TcpServer {
  5. public static void main(String[] args) throws IOException {
  6. if(args.length<1) {
  7. System.out.println("Usage: program pornum");
  8. return;
  9. }
  10. int port = Integer.parseInt(args[0]);
  11. System.out.println("Listenting on port: "+port);
  12. ServerSocket tcpsock = new ServerSocket(port);
  13. while(true) {
  14. try {
  15. Socket connection = tcpsock.accept();
  16. System.out.println("Connection from: "+connection.getInetAddress().getHostAddress()+":"+connection.getPort());
  17. connection.close();
  18. } catch(Throwable t) {
  19. t.printStackTrace();
  20. }
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment