Question

Build a server application which will reverse the order of a string received from a client. When client connects, a new thread is started to handle an interactive dialog in which the client sends in a...

Build a server application which will reverse the order of a string received from a client. When client connects, a new thread is started to handle an interactive dialog in which the client sends

in a string input by the user and the server thread sends back the letters of the string in reverse order. Allow the client to send 10 Strings.

In Java.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

UDPClient.java:-
importjava.io.*;
importjava.net.*;
classUDPClient
{
publicstaticvoidmain(Stringargs[])throwsException
{
BufferedReaderinFromUser=
newBufferedReader(newInputStreamReader(System.in));
DatagramSocketclientSocket=newDatagramSocket();
InetAddressIPAddress=InetAddress.getByName("localhost");
byte[]sendData=newbyte[1024];
byte[]receiveData=newbyte[1024];
Stringsentence=inFromUser.readLine();
sendData=sentence.getBytes();
DatagramPacketsendPacket=newDatagramPacket(sendData,sendData.length,IPAddress,
9876);
clientSocket.send(sendPacket);
DatagramPacketreceivePacket=newDatagramPacket(receiveData,receiveData.length);
clientSocket.receive(receivePacket);
StringmodifiedSentence=newString(receivePacket.getData());
System.out.println("FROMSERVER:"+modifiedSentence);
clientSocket.close();
}
}
UDPServer.java:-
importjava.io.*;
importjava.net.*;
classUDPServer
{
publicstaticvoidmain(Stringargs[])throwsException
{
DatagramSocketserverSocket=newDatagramSocket(9876);
byte[]receiveData=newbyte[1024];
byte[]sendData=newbyte[1024];
while(true)
{
DatagramPacketreceivePacket=newDatagramPacket(receiveData,
receiveData.length);
serverSocket.receive(receivePacket);
Stringsentence=newString(receivePacket.getData());
System.out.println("RECEIVED:"+sentence);
InetAddressIPAddress=receivePacket.getAddress();
intport=receivePacket.getPort();
StringreverseSentence=sentence.reverse();
sendData=capitalizedSentence.getBytes();
DatagramPacketsendPacket=
newDatagramPacket(sendData,sendData.length,IPAddress,port);
serverSocket.send(sendPacket);
System.out.println("ModifiedmessagepassedtoUDPclient");
}
}

Add a comment
Know the answer?
Add Answer to:
Build a server application which will reverse the order of a string received from a client. When client connects, a new thread is started to handle an interactive dialog in which the client sends in a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using the programming language of your choice, write a client application which: Connects to a network...

    Using the programming language of your choice, write a client application which: Connects to a network service, then Asks for version information, then Receives the response, then Disconnects and Prints out the response. Detail: The program will take no input from the user. When your program is executed, it should connect to IP address 64.183.98.170 on port 3800. Upon successful connection, send the string: version\n where \n is an end of line marker. The server will respond with a string...

  • TASK Your task is to build a palindrome from an input string. A palindrome is a...

    TASK Your task is to build a palindrome from an input string. A palindrome is a word that reads the same backward or forward. Your code will take the first 5 characters of the user input, and create a 9- character palindrome from it. Words shorter than 5 characters will result in a runtime error when you run your code. This is acceptable for this exercise – we will cover input validation in a later class. Some examples of input...

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • Let’s build a dynamic string tokenizer! Start with the existing template and work on the areas...

    Let’s build a dynamic string tokenizer! Start with the existing template and work on the areas marked with TODO in the comments: Homework 8 Template.c Note: If you turn the template back into me without adding any original work you will receive a 0. By itself the template does nothing. You need to fill in the code to dynamically allocate an array of strings that are returned to the user. Remember: A string is an array. A tokenizer goes through...

  • For this project, you are tasked with creating a text-based, basic String processing program that performs...

    For this project, you are tasked with creating a text-based, basic String processing program that performs basic search on a block of text inputted into your program from an external .txt file. After greeting your end user for a program description, your program should prompt the end user to enter a .txt input filename from which to read the block of text to analyze. Then, prompt the end user for a search String. Next, prompt the end user for the...

  • Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such...

    Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaration, initialization, storing, retrieving, and processing elements. • Effectively manipulating and using ArrayList objects. • Becoming familiar with the use of arrays as method arguments and how array elements are passed to and returned from the called method. • Mastering the use of various debugging tools available on the Eclipse IDU. Important: EVERY one of the following Activities MUST be in a separate...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT