Skip to content

Commit d02a934

Browse files
committed
Create UDPReceiver.java
1 parent a99abac commit d02a934

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//version 11.1
2+
3+
//It is the receiver of the sent datagram packet
4+
5+
import java.net.*;
6+
7+
class UDPReceiver
8+
{
9+
public static void main(String s[])
10+
{
11+
try
12+
{
13+
System.out.println("receiver started");
14+
DatagramSocket receiver=new DatagramSocket(3000);
15+
16+
while(true)
17+
{
18+
byte b[]=new byte[100];
19+
DatagramPacket packet=new DatagramPacket(b , b.length);
20+
receiver.receive(packet);
21+
String str=new String(b);
22+
if(str.trim().length()==0)
23+
break;
24+
25+
System.out.println("Msg recd: "+str);
26+
}
27+
}
28+
catch(Exception e)
29+
{ e.printStackTrace();
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)