Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Server client (Socket programming)  RSS feed

 
Medes Agri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

there is a client and two servers. the client must communicate with them simultaneously and get data from them (a string).

I have used threading and it works but with a little problem.

the problem is when i exceute the client, sometimes it gets nothing from servers it just generates "press any key to continue ..." and sometimes it gets data from one of the servers and sometimes it gets the data from both and it works correct. I dont know why?

I am very gratefull for your response and advices

here is a bit of my code:
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see you writing anything in your server, but we'll leave that as a typo for now.
One problem I see is your use of ready(). If you look at the javadoc for java.io.Reader you'll see ready() doesn't do what you think it does. It does not indicate if a stream is connected, it returns if the stream will block, which is perfectly acceptable in your circumstances.
 
Medes Agri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much,

what i must to do know? what is the answer, do i use while(in.readLine() != null) instead of while(in.ready()) ?

do i must have more on my servers if i just want that thay send a string to the client?

thanks again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!