aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Socket flush hangs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Socket flush hangs" Watch "Socket flush hangs" New topic
Author

Socket flush hangs

Kevin Halk
Greenhorn

Joined: Feb 09, 2010
Posts: 10
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

Joined: Sep 20, 2010
Posts: 3647
    
  17

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

Joined: Feb 09, 2010
Posts: 10
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

Joined: Sep 20, 2010
Posts: 3647
    
  17

Can you show us the complete method you're using?
Kevin Halk
Greenhorn

Joined: Feb 09, 2010
Posts: 10


Stephan van Hulst wrote:Can you show us the complete method you're using?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

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

Joined: Oct 27, 2005
Posts: 19720
    
  20

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: Socket flush hangs