Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Client-Server communication; client freezes

 
Khalil Salman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the story:
Clients sends a request, server reads that request, and sends a response, lastly client reads the response.

There will be multiple clients so I tried to implement it using threads in the server code to be able to continue listening for new requests.
But in the last step the client freezes when I say read the response from the server. I mean the client sends a request successfully, and the server reads it and responses successfully but the client then cannot get the response; freezes.

Here is the code:

This is for the client:


And here is the server:


And the server's response sender run() function:


Thank you for any help..
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont't println to a Socket: http://developer.apple.com/technotes/tn/tn1157.html

And don't ignore exception: } catch(Exception exc){}
That's a no-no.
 
Paul Clapham
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really want the server to be multi-threaded then this is wrong:

To start a Thread running, do this:

And "handler" would need to be a Thread, not a Runnable.
 
Khalil Salman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys.

Yeah I commented out println() parts and change the Runnable to Thread. And I replaced handler.run() with handler.start().
But nothing changed.

Something else should be missing. Something that I don't know but very critical.
Gosh 15-20 lines of code but I cannot get it working.
 
Paul Clapham
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So show us the new code, the version which doesn't use PrintWriter and which writes your exceptions to somewhere you can look at them.
 
Khalil Salman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright. Now I see what you mean by saying "don't println to socket."
Don't use PrintWriter!..

Ulf, the link you gave for "don't println to socket" redirects me to somewhere else not to an article.
So please check it for future references.

Thank you guys anyway, the issue is resolved.

Here is the code, (maybe someone needs it in the future)

The server code:


server's response sender:


And the client:

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Huh, kind of stupid to break long-established URLs; but here is the article.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic