• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

another multi theaded socket question..

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks...i'll try that...thanks again...
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic