简体   繁体   中英

Java socket read method returns -1

I'm writing server side application which handle incoming request from Flash over RTMP. On the server side I've got simple blocking IO.

I noticed that over 10-30 % sessions are terminated when InputStream.read returns -1, which should indicate end of stream. These requests are terminated at the very beginning of user sessions, so I don't really think users close their browser...

Less often java.net.SocketException: Broken pipe exception occurs on attempt to write to the stream.

It's look rather suspicious, that I receive end of the steam so many time. What could be the reason of receiving end of stream at the very beginning of conversation ?

The client has closed the connection, from your point of view prematurely. This explains both the -1 and the 'broken pipe'. Just accept it and deal with it. In general a peer should be able to exit the conversation at any step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM