View RSS Feed

Java Socket

Socket programming and networking examples in Java.

  1. Receiving Data via a DatagramSocket

    by , 04-25-2012 at 10:37 PM
    Data is received through a DatagramSocket by creation of the DatagramPacket firstly & then by receiving data through DatagramSocket receiver() method into it. Example is as following:
    Java Code:
    DatagramSocket datagramSocket = new DatagramSocket(80);
    byte[] buffer = new byte[10];
    DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
    datagramSocket.receive(packet);
    Way of instantiation of the DatagramSocket shall be noticed along with the parameter ...