Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- /**
- * A subclass of DatagramSocket which contains
- * methods for sending and receiving messages
- */
- public class MyDatagramSocket extends DatagramSocket {
- static final int MAX_LEN = 10;
- MyDatagramSocket(int portNo) throws SocketException {
- super(portNo);
- }
- public void sendMessage(InetAddress receiverHost, int receiverPort,
- String message) throws IOException {
- byte[] sendBuffer = message.getBytes();
- DatagramPacket datagram =
- new DatagramPacket(sendBuffer, sendBuffer.length,
- receiverHost, receiverPort);
- this.send(datagram);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement