List of usage examples for java.net DatagramSocket getLocalSocketAddress
public SocketAddress getLocalSocketAddress()
From source file:Main.java
public static void main(String[] args) throws Exception { final int LOCAL_PORT = 12345; final String SERVER_NAME = "localhost"; DatagramSocket udpSocket = new DatagramSocket(LOCAL_PORT, InetAddress.getByName(SERVER_NAME)); System.out.println("Created UDP server socket at " + udpSocket.getLocalSocketAddress() + "..."); while (true) { System.out.println("Waiting for a UDP packet..."); DatagramPacket packet = new DatagramPacket(new byte[1024], 1024); udpSocket.receive(packet);/*from w w w.j a v a 2s.c om*/ displayPacketDetails(packet); udpSocket.send(packet); } }
From source file:Main.java
public static void main(String args[]) { try {/*from w w w . j a va 2 s . c o m*/ InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); // Send the datagram packet ds.send(dp); System.out.println(ds.getLocalSocketAddress()); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.restcomm.sbc.media.MediaZone.java
private String toPrint(DatagramSocket socket) { return "Socket Bound to " + socket.getLocalSocketAddress() + " Connected to " + socket.getRemoteSocketAddress(); }