0

Apologize for repeating question. I have already tried the solution given, doesn't work in my case. For disconnection i have already handled socket exception , 0 bytes received for handling disconnection. This works perfectly in case of server shutdown , lan disconnection. But when internet disconnects, socket does not disconnects immediately. After internet disconnection when i sent some data on socket, that time socket get disconnected. How do i immediately detect socket disconnection in case of internet disconnection. I have tried Socket.Poll().This doesn't works. My code is written in c# .net

Nikita P
  • 41
  • 4
  • As you said, this is a repeat question. Closing. There are multiple answers for this on Stack Overflow. Note, that in the linked dupe the top answer is wrong and everyone should downvote who comes along. – usr Dec 12 '15 at 12:21
  • I have already referred to above link. the solution does not works in my case i have tried following solution public static bool IsConnected(this Socket socket) { try { return !(socket.Poll(1, SelectMode.SelectRead) && socket.Available == 0); } catch (SocketException) { return false; } } – Nikita P Dec 12 '15 at 12:43
  • You have taken the bad first answer. Read the second one which tells you it's impossible. And yes, the first answer does not work and please downvote it. – usr Dec 12 '15 at 12:45
  • I have mentioned in question socket.Poll() returns true even if internet is disconnected. – Nikita P Dec 12 '15 at 12:46
  • I am able to detect disconnection from server side say if server shutdowns or server closes client socket. I am looking for method where i can detect internet disconnection not instantly but say after 10 or 15 seconds – Nikita P Dec 12 '15 at 12:49
  • I understand that and it's not possible. I'm running out of ways to tell you that. Read more stack overflow content on the topic to understand *why*. Right now you seem to look to copy and paste the magic source code that will make it happen. If the network drops, how is the other side supposed to find out when there is no further communication? – usr Dec 12 '15 at 12:51
  • Allow me to help - IT IS NOT POSSIBLE. It cannot be done. Doing what you ask is impossible. Its is not possible because 'the internet' does not exist as an entitiy that you can connect to. It is not possible to determine if you are connected to 'the internet'. Anyone who suggests a method of detemining an internet connection is deluded. – Martin James Dec 12 '15 at 17:22

0 Answers0