News:

Build a stunning handcrafted website with IT Acumens

Main Menu

Socket isConnected Example

Started by VelMurugan, Jan 07, 2009, 11:47 PM

Previous topic - Next topic

VelMurugan

Socket isConnected Example

Socket class isConnected example. This example shows you how to use isConnected method.

Socket class isConnected example. public boolean isConnected() Returns the connection state of the socket.

Here is the code

/*
* @ # IsConnected.java
* A class repersenting use to IsConnected method
* of NumberFormat class in java.text package
* version 17 June 2008
* author Rose India
*/

import java.net.*;

public class IsConnected {

    public static void main(String args[]) throws Exception {

        Socket socket = new Socket();

        System.out.println("Connection state of the socket " + socket.isConnected());
        //Connects this socket to the server.
        socket.connect(new InetSocketAddress("192.168.10.211", 8080));

        System.out.println("Connection state of the socket " + socket.isConnected());
        socket.close();
    }
}


Output

Connection state of the socket false
Connection state of the socket true

Source : codingdiary