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, int timeout) throws IOException Connects this socket to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.

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 Connect1 {

    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),10);

        //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