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

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US