The following Client side Java code can send a message to the server side via UDP socket. The client side Java code and the server side Java code are running in two different hosts respectively. The server side host name is “MyFileServer”. The server side receives the message and converts all the letters in the message received to uppercase, then sends the modified message back to the client side. Please read the code carefully, and fill out the blanks with appropriate code to make them work.
===Client Side Java code below======
import java.io.*;
import java.net.*;
class UDPClient {
public static void main(String args[]) throws Exception
{
DatagramSocket clientSocket = new __________;
InetAddress IPAddress = InetAddress.getByName("________");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = “This is a Test for cpsc5157U class”;
________ = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.______, IPAddress, _____);
clientSocket.______;
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(________);
String modifiedSentence = new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
clientSocket.close();
}
}
=======End of Client Side Code ===========
==== Server Side Java Code below===========
import java.io.*;
import java.net.*;
class UDPServer {
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new ____________(34926);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while(true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String(receivePacket.getData());
InetAddress MyAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(______, sendData.length, _______, port);
serverSocket.send(sendPacket);
}
}
}
========= End of Server Side Java Code============
If you have any problem with the code feel free to comment.
Client
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
class UDPClient {
public static void main(String args[]) throws Exception {
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName(null);
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = "This is a Test for cpsc5157U class";
sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 34926);
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();
}
}
Server
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
class UDPServer {
public static void main(String args[]) throws Exception {
DatagramSocket serverSocket = new DatagramSocket(34926);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while (true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String(receivePacket.getData());
InetAddress MyAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, MyAddress, port);
serverSocket.send(sendPacket);
}
}
}
Output

The following Client side Java code can send a message to the server side via UDP...
Q7 The following Client side Java code can send a message to the server side via UDP socket. The client side Java code and the server side Java code are running in two different hosts respectively. The server side host name is “MyFileServer”. The server side receives the message and converts all the letters in the message received to uppercase, then sends the modified message back to the client side. Please read the code carefully, and fill out the blanks...
Overview UDP is a transport layer protocol that provides no reliability. This project aims to show how to implement extra features for the protocol in the application layer. The project will develop a new version of UDP protocol called UDPplus which provides reliable connection oriented between a client and a UDPplus sever. The UDPplus is implemented at application layer using UDP protocol only. Basic Scenario The UPDplus is a simple bank inquiry application where the client sends full name and...
Using Eclipse I am trying to pass a string of numbers from the client class to the server. The server will then compute the sum, average max and min from the numbers and then pass it back to the client. The client will then display the answers in a text field. This is what i have so far for the class client and not sure how to proceed or if it's correct. i also am not sure how to complete...
I need help with my IM (instant messaging) java program, I created the Server, Client, and Message class. I somehow can't get both the server and client to message to each other. I am at a roadblock. Here is the question below. Create an IM (instant messaging) java program so that client and server communicate via serialized objects (e.g. of type Message). Each Message object encapsulates the name of the sender and the response typed by the sender. You may...
I need help with this assignment, please; Programming Assignment 3: UDP Pinger Lab In this lab, you will study a simple Internet ping server written in the Java language, and implement a corresponding client. The functionality provided by these programs is similar to the standard ping programs available in modern operating systems, except that they use UDP rather than Internet Control Message Protocol (ICMP) to communicate with each other. (Java does not provide a straightforward means to interact with ICMP.)...
My client java a simple client program java .net import java.io*i public class MyClient (public static void main(String args() thrown IO Exception (part I: initialize rocket and stream BufferedReader inFromUser - new BufferedReader(new inputStreamReader(System in)); Socket clientSocket - new Socket(___. ___); DataOutputStream oldToServer - new DataOutputStream(clientSocket.getOutputStrea, ())); part 2: interact with server
Using java socket programming rewrite the following program to handle multiple clients simultaneously (multi threaded programming) import java.io.*; import java.net.*; public class WelcomeClient { public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println( "Usage: java EchoClient <host name> <port number>"); System.exit(1); } String hostName = args[0]; int portNumber = Integer.parseInt(args[1]); try ( Socket kkSocket = new Socket(hostName, portNumber); PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true); BufferedReader in = new BufferedReader( new InputStreamReader(kkSocket.getInputStream())); ) { BufferedReader...
Java(Eclipse). The task will create a server and client and send a message from the client to the server. We will have two classes NetworkClient and NetworkServerListener classes. These will each have a main to run from the command line The NetworkServerListener class will listen for a client connection from NetworkClient , receive a message, display the message to the console (stdout) and exit. The NetworkClient class will create a connection to the NetworkServerListener and send a message to the...
Error: Main method not found in class ServiceProvider, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application This is the error im getting while executing the following code Can you modify the error import java.net.*; import java.io.*; public class ServiceProvider extends Thread { //initialize socket and input stream private Socket socket = null; private ServerSocket server = null; private DataInputStream in = null; private DataOutputStream out = null; private int...
Modify the socket-based date server below so that the server services each client request in a separate thread. import java.net.*; import java.io.*; public class DateClient { public static void main(String[] args) { try { /* make connection to server socket */ Socket sock = new Socket(“127.0.0.1”,6013); InputStream in = sock.getInputStream(); BufferedReader bin = new BufferedReader(new InputStreamReader(in)); /* read the date from the socket */ String line; while ( (line = bin.readLine()) != null) System.out.println(line); /* close the socket connection*/ sock.close(); ...