• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

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...
 
Master Rancher
Posts: 43045
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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic