-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDPC.java
More file actions
27 lines (27 loc) · 975 Bytes
/
UDPC.java
File metadata and controls
27 lines (27 loc) · 975 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.*;
import java.net.InetAddress;
import java.util.Scanner;
class UDPC
{
public static void main(String[] args)throws Exception
{
BufferedReader inFromUser=new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
DatagramSocket clientSocket=new DatagramSocket();
InetAddress IPAddress=InetAddress.getByName("localhost");
byte[] sendData=new byte[1024];
byte[] receiveData=new byte[1024];
System.out.println("Enter the sting to be converted in to Upper case");
String sentence=sc.nextLine();
sendData=sentence.getBytes();
DatagramPacket sendPacket=new DatagramPacket(sendData,sendData.length,IPAddress,9876);
clientSocket.send(sendPacket);
DatagramPacket receivePacket=new DatagramPacket(receiveData,receiveData.length);
clientSocket.receive(receivePacket);
String modifiedSentence=new String(receivePacket.getData());
System.out.println("FROM SERVER:"+modifiedSentence);
clientSocket.close();
sc.close();
}
}