Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket flush hangs

 
Kevin Halk
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I'm writing to a socket using a BufferedWriter and I'm having a strange problem of the .flush() command hanging. I'm using fairly standard methods to send the data as far as I can tell. Unfortunately I don't have access to the server-side code as it is a third-party solution.

Does anybody know what would cause a .flush() call to hang, or how I can detect or fix this once it's happening?



 
Stephan van Hulst
Bartender
Pie
Posts: 6083
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kevin,

How do you know the flush hangs? Did you put println statements before and after it? If so, then couldn't it be that the flush is throwing an exception which you are catching somewhere without printing a diagnostic message?
 
Kevin Halk
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right, there was a log line right before and right after. It's surrounded with a catch IOException as well as a catch Exception and neither are executed.

I'm wondering if there is some timeout setting with regards to this?

Stephan van Hulst wrote:Hi Kevin,

How do you know the flush hangs? Did you put println statements before and after it? If so, then couldn't it be that the flush is throwing an exception which you are catching somewhere without printing a diagnostic message?
 
Stephan van Hulst
Bartender
Pie
Posts: 6083
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the complete method you're using?
 
Kevin Halk
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Stephan van Hulst wrote:Can you show us the complete method you're using?
 
Stephan van Hulst
Bartender
Pie
Posts: 6083
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I missed your post. Can you try it without the newline? It shouldn't really make a difference, but I've heard that new lines sometimes don't play nice with sockets. Otherwise I'm stumped.
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't println to a Socket. That includes using newLine(). Use a hard coded \r, \n or \r\n, whichever one the protocol is expecting (HTTP for instance uses \r\n).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic