944,111 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 640
  • Java RSS
Oct 27th, 2007
0

Multithreading.....Help pls

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bagi is offline Offline
24 posts
since Mar 2006
Oct 27th, 2007
0

Re: Multithreading.....Help pls

What do you know about threads?

What exactly about adding threading to this program do you not understand?

After each connection, you need to start a new thread using the socket created by the connection. What else do you need to know?

If you don't know how to make and/or start the thread, then please consult the threading tutorials at Sun first, then come back and try this.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: SOAP-XML-Exceptions
Next Thread in Java Forum Timeline: insert pictures and movies in oracle9i using jdbc





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC