• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Client-Server communication; client freezes

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28264
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28264
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Huh, kind of stupid to break long-established URLs; but here is the article.
 
reply
    Bookmark Topic Watch Topic
  • New Topic