forked from Pythonista7/ComputerNetworksLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathudpClient.java
More file actions
29 lines (22 loc) · 689 Bytes
/
udpClient.java
File metadata and controls
29 lines (22 loc) · 689 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
28
29
/*
Write a program on datagram sockets for client/server to display message on client side,typed on server side.
*/
import java.io.*;
import java.net.*;
class udpClient
{
public static void main(String[] args) throws IOException
{
//Set the port number on which the client must communicate to the server.
DatagramSocket ds=new DatagramSocket(2345);
String msg;
byte[] buf=new byte[100];
while(true)
{
DatagramPacket rdp=new DatagramPacket(buf,buf.length);
ds.receive(rdp);
msg=new String(rdp.getData(),rdp.getOffset(),rdp.getLength());
System.out.println(msg);
}
}
}