How to Create a New Streaming Socket Connected to Target Host

public Socket (String dstName, int dstPort) was added in API level 1
Creates a new streaming socket connected to the target host specified by the parameters dstName and dstPort. The socket is bound to any available port on the local host.
This implementation tries each IP address for the given host name (in RFC 3484 order) until it either connects successfully or it exhausts the set.
dstName - the target host name or IP address to connect to.
dstPort - the port on the target host to connect to.
UnknownHostException - if the host name could not be resolved into an IP address.
IOException - if an error occurs while creating the socket.

1. Declare a Socket named mySocket.

2. In the MainActivity. add the below imports to the import section. 

4. In the onCreate, add the below code to create a new streaming socket connected to a target host. For example, you can connect to your IP address (my example: with a port address of 8888. The e.printStackTrace will be sent to your LogCat. For direct errors, you may add a toast

try {
mySocket = new Socket("", 8888);
} catch (UnknownHostException e) {
//Toast.makeText(this, "Socket Error: UnknownHostException", Toast.LENGTH_LONG).show();
} catch (IOException e) {
//Toast.makeText(this, "Socket: IOExcpetion", Toast.LENGTH_LONG).show();


5. Compile and run!