0% found this document useful (0 votes)
10 views2 pages

Exp 17

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Exp 17

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

M.M.

Polytechnic, Thergaon

//Exp171
//EXP171 Client Program
import java.io.*;
import java.net.*;
import java.util.*;

class exp171UDPClient
{
public static void main(String args[]) throws Exception
{
Scanner sc=new Scanner(System.in);
DatagramSocket Csocket = new DatagramSocket();
InetAddress IP = InetAddress.getByName("localhost");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = sc.next();
sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IP,
8765);
Csocket.send(sendPacket);
DatagramPacket receivePkt = new DatagramPacket(receiveData, receiveData.length);
Csocket.receive(receivePkt);
String modifiedSentence = new String(receivePkt.getData());
System.out.println("FROM SERVER: " + modifiedSentence);
Csocket.close();
}
}

//EXP171 Server Program


import java.io.*;
import java.net.*;
import java.lang.*;

class exp171UDPServer
{
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new DatagramSocket(8765);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];

while(true)
{

AJP Expt-17 1 Mrs. Chavan P.P.


M.M.Polytechnic, Thergaon

DatagramPacket receivePacket = new DatagramPacket(receiveData,


receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String( receivePacket.getData());
System.out.println("RECEIVED: " + sentence);

String h=new String("Hello ");


String n=new String( h.concat(sentence) );
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();

sendData = n.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length,
IPAddress, port);
serverSocket.send(sendPacket);
}
}
}

AJP Expt-17 2 Mrs. Chavan P.P.

You might also like