Quantcast
Channel: Java mon amour
Viewing all articles
Browse latest Browse all 1124

ServerSocket: listening on a port in 2 seconds

$
0
0




import java.net.InetAddress;
import java.net.ServerSocket;


public class SS {
public static void main(String[] args) throws Throwable {
InetAddress inet = InetAddress.getByName("192.168.6.110");
ServerSocket ss = new ServerSocket(7001, 100, inet);
ss.accept();
}
}




After that, if you run
ss -ln | grep 7001
you should see your fish swimming, and be able to telnet into it.
(ah of course: javac SS.java, java SS) To check if something is listening on an IP/port:



import java.net.InetAddress;
import java.net.Socket;


public class CS {
public static void main(String[] args) throws Throwable {
InetAddress inet = InetAddress.getByName("192.168.6.110");
Socket so = new Socket(inet, 7001);
so.getInputStream();
}
}




Viewing all articles
Browse latest Browse all 1124

Trending Articles