DatagramSocket Connect1() Example
Connects this socket to a remote socket address (IP address + port number).
DatagramSocketclass Connect1() method example. This example shows you how to use Connect1() method.This method Connects this socket to a remote socket address (IP address + port number).
Here is the code:-
/**
* @Program that Connects this socket to a remote socket address .
* Connect1.java
* Author:-RoseIndia Team
* Date:-20-jun-2008
*/
import java.net.*;
public class Connect1 {
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket();
SocketAddress s = new InetSocketAddress("girish-desktop", 8089);
System.out.println("Remote socket address: " + ds.getInetAddress());
//Connects this socket to a remote socket address .
ds.connect(s);
System.out.println(ds.getInetAddress());
}
} |
Output of the program:-
Remote socket address: null
girish-desktop/127.0.1.1 |
|