Socket connect Example
Socket class connect example. This example shows you how to use connect method.
Socket class connect example. public void connect(SocketAddress endpoint) throws IOException Connects this socket to the server.
Here is the code
/*
* @ # Connect.java
* A class repersenting use to connect method
* of Socket class in java.net package
* version 19 June 2008
* author Rose India
*/
import java.net.*;
public class Connect {
public static void main(String args[]) throws Exception {
Socket socket = new Socket();
//Connects this socket to the server.
socket.connect(new InetSocketAddress("192.168.10.80", 9090));
//return getInetAddress
InetAddress inetaddress = socket.getInetAddress();
System.out.println("Inet Address is " + inetaddress);
//close socket
socket.close();
}
} |
Output
| Inet Address is /192.168.10.80 |
|