Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

client doesn't detect server drop

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My client waits at the select cmd for any data sent to it via the server. The server can drop off unexpectedly and my client should detect this and attempt a reconnect, but it never detects the server is dead. Why doesn't this disconnect trigger an exception? Does it have anything to do with using non-blocking IO?

My client will just sit at the select forever when the server socket is closed and subsequently the thread running the server is killed. If I happen to close the
DataOutputStream output
then, my client will be triggered that a new read has come in and he will attempt to read from the socket, but will get back a read count of -1. I don't know how he is able to read from a socket that has been shutdown without an I/O exception being thrown:

I stop the server like this and directly after this thread dies:


This is the code for the client. He just sits at the select (which is configured for SelectionKey.OP_READ ), but never detects that the server has dropped. When I close down output, he gets a read cmd and attempts to read from the socket.

Client is configured this way.



Main processing loops


[ December 16, 2004: Message edited by: N Goldsmith ]

[ December 16, 2004: Message edited by: N Goldsmith ]

[ December 16, 2004: Message edited by: N Goldsmith ]

[ December 16, 2004: Message edited by: N Goldsmith ]
[ December 16, 2004: Message edited by: N Goldsmith ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic