-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUDPclient.java
More file actions
28 lines (27 loc) · 825 Bytes
/
UDPclient.java
File metadata and controls
28 lines (27 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.io.*;
import java.net.*;
public class UDPclient
{
public static void main(String [] args)
{
DatagramSocket skt = null;
try
{
skt=new DatagramSocket();
String msg = "UDP";
byte b[] = msg.getBytes();
InetAddress host = InetAddress.getByName("127.0.0.1");
int serverSocket = 6788;
DatagramPacket request = new DatagramPacket(b,b.length,host,serverSocket);
skt.send(request);
byte buffer[] = new byte[1000];
DatagramPacket reply = new DatagramPacket(buffer,buffer.length);
skt.receive(reply);
System.out.println("Client Received: "+new String(reply.getData()));
skt.close();
}
catch(Exception E)
{
}
}
}