Client side:
import java.io.*;
import java.net.*;
class TCPClient
{
public static void main(String[] args) throws Exception
{
String sentence;
String modifiedSentence;
BufferedReader inFromUser = new BufferedReader (new InputStreamReader(System.in));
while(true)
{
Socket clientSocket = new Socket("hostname", 5678);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
//clientSocket.close();
}
}
}
Server side:
import java.io.*;
import java.net.*;
class TCPServer
{
public static void main(String[] args) throws Exception
{
String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(5678);
while(true)
{
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
}
I have read these codes in my textbook. It works. But in this given source code, i want it to change to the multithreading.
What should I add to my source code.
Thank you so much, I really need it.
bagi