-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDPclient.java
More file actions
32 lines (32 loc) · 1014 Bytes
/
UDPclient.java
File metadata and controls
32 lines (32 loc) · 1014 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
30
31
32
import java.io.*;
import java.net.*;
class UDPclient
{
public static byte buf[] = new byte[1024];
public static int cport = 789, sport = 790;
public static void main(String[] a) throws IOException
{
DatagramSocket clientsocket = new DatagramSocket(cport);
DatagramPacket dp = new DatagramPacket(buf, buf.length);
BufferedReader dis = new BufferedReader(new InputStreamReader(System.in));
InetAddress ia = InetAddress.getLocalHost();
System.out.println("Client is Running... Type 'STOP'to Quit");
while(true)
{
System.out.print("Client :");
String str = new String(dis.readLine());
buf = str.getBytes();
if(str.equals("STOP"))
{
System.out.println("Terminated...");
clientsocket.send(new DatagramPacket(buf,str.length(), ia, sport));
break;
}
clientsocket.send(new DatagramPacket(buf,str.length(), ia, sport));
clientsocket.receive(dp);
String str2 = new String(dp.getData(), 0,dp.getLength());
System.out.println("Server: " + str2);
}
clientsocket.close();
}
}