-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUDPServer.java
executable file
·25 lines (24 loc) · 1.04 KB
/
UDPServer.java
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
import java.io.*;
import java.net.*;
class UDPServer
{
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new DatagramSocket(9877);
byte[] receiveData = new byte[128];
while(true)
{
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String( receivePacket.getData(),0,receivePacket.getLength());
System.out.println("RECEIVED: " + sentence);
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
//String capitalizedSentence = sentence.toUpperCase();
//sendData = capitalizedSentence.getBytes();
//DatagramPacket sendPacket =
//new DatagramPacket(sendData, sendData.length, IPAddress, port);
//serverSocket.send(sendPacket);
}
}
}