• Post Reply Bookmark Topic Watch Topic
  • New Topic

another multi theaded socket question..

 
yhel barni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i started in this project...

i have chat program and it has a server program that accepts connection request from clients through sockets..
every time a new socket connects to the server the server program creates a new thread for that specific client..
then that client-specific thread handles the receiving and sending of messages...

first question: how can i make the client-specific thread determine to whom the message is for...
next question:i been having problems with using

BufferedReader reader=new BufferedReader(new InputStreamReader(s.getInputStreamReader()));

String message=reader.readLine()//this line seems to cause all the problem, the execution of my client-specific thread seems to stop when it execute this line of code...
//i use this line in accepting message to the socket either from the client going to the server or vice versa...
//there is this error that says that the connection was reset...

thanks in advance...
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding the line end problem: Don't println to a Socket. If you're using readLine, then you're very likely using println as well.

You're also using the platform default encoding, which is very likely to cause problems as well - make sure you use the same encoding on both the client and the server.

As to routing messages to the correct client: the client needs to send the target client ID with each message.
 
yhel barni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks...i'll try that...thanks again...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!