Skip to content

Instantly share code, notes, and snippets.

@mr-fool
Last active January 1, 2016 15:39
Show Gist options
  • Save mr-fool/8165363 to your computer and use it in GitHub Desktop.
Save mr-fool/8165363 to your computer and use it in GitHub Desktop.
Simple networking attempt
import java.net.Socket;
/**
* @author mr-fool
* @param a simple network tool*/
public class SocketProxy extends Thread {
public static void main (String[] args) {
String address = args[0];
int port = Integer.parseInt(args[1]);
/**
* @param trying to connect
* @param set timeout to 9000 */
try {
System.out.println ("Attempting to connect " + address + ":" + port);
Socket connection = new Socket(address,port);
System.out.println("Connection status: " + connection.isConnected() );
connection.setSoTimeout(9000);
System.out.println ("Connected to " + connection. getRemoteSocketAddress());
System.out.println ("Time out is setted to 9000 milisecond");
}
catch (Exception e){
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment