Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment