About
Auto slice and merge datagram packet, no need care about packet size.
Download
Add maven repository url https://dl.bintray.com/pacey6/maven
.
Download the latest JAR at the coordinates com.pacey6.net:datagram:1.0
.
Source Code
See Github.
Usage
- Create MultiDatagramSocket:
MulticastSocket multicastSocket = new MulticastSocket(1027);
MultiDatagramSocket<MulticastSocket> multiDatagramSocket = new MultiDatagramSocket<>(multicastSocket);
- Receive packet, method
receive()
will block current thread:
MultiDatagramPacket multiDatagramPacket = multiDatagramSocket.receive();
String msg = new String(multiDatagramPacket.getData());
- Send a packet:
String msg = "Hello world";
MultiDatagramPacket multiDatagramPacket = new MultiDatagramPacket(msg.getBytes(), InetAddress.getLocalHost(), 1027);
multiDatagramSocket.send(multiDatagramPacket);