Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Service No SocketException

C# Service No SocketException

Scheduled Pinned Locked Moved C#
csharpcomsysadminhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vadim Tabakman
    wrote on last edited by
    #1

    Hi all, I am starting a C# Windows Service. In the Service class, I've added an object to the service class, and OnStart, I initialize this object which creates a socket listener. I use Asynchronous Sockets. So BeginAccept/EndAccept and BeginReceive/EndReceive is used. My client app connects fine to the server and disconnects fine, but on the server end, the server doesn't recognize the client disconnection. I receive a OnDataReceived message, which then triggers the EndReceive. I have a sample client-server application that does exactly the same thing, which I've cut-n-pasted from. In the sample, the EndReceive throws a SocketException with the error code 10054 (disconnection). But in my code, the EndReceive just returns 0 bytes received, and no exception is thrown. Can anyone point me in the right direction? Cheers, "If you're too careful, your whole life can become a f---in' grind." - Mike McD (Rounders)

    S 1 Reply Last reply
    0
    • V Vadim Tabakman

      Hi all, I am starting a C# Windows Service. In the Service class, I've added an object to the service class, and OnStart, I initialize this object which creates a socket listener. I use Asynchronous Sockets. So BeginAccept/EndAccept and BeginReceive/EndReceive is used. My client app connects fine to the server and disconnects fine, but on the server end, the server doesn't recognize the client disconnection. I receive a OnDataReceived message, which then triggers the EndReceive. I have a sample client-server application that does exactly the same thing, which I've cut-n-pasted from. In the sample, the EndReceive throws a SocketException with the error code 10054 (disconnection). But in my code, the EndReceive just returns 0 bytes received, and no exception is thrown. Can anyone point me in the right direction? Cheers, "If you're too careful, your whole life can become a f---in' grind." - Mike McD (Rounders)

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      I think that's the expected behavior, according to the MSDN documentation. " If the remote host shuts down the Socket connection with the Shutdown method, and all available data has been received, the EndReceive method will complete immediately and return zero bytes". You can therefore assume that if you get 0 bytes received in EndReceive, the remote client has disconnected. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      V 1 Reply Last reply
      0
      • S S Senthil Kumar

        I think that's the expected behavior, according to the MSDN documentation. " If the remote host shuts down the Socket connection with the Shutdown method, and all available data has been received, the EndReceive method will complete immediately and return zero bytes". You can therefore assume that if you get 0 bytes received in EndReceive, the remote client has disconnected. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        V Offline
        V Offline
        Vadim Tabakman
        wrote on last edited by
        #3

        Thanks Senthil, I didn't see that in the documentation. Much appreciated. Jub "If you're too careful, your whole life can become a f---in' grind." - Mike McD (Rounders)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups