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. Strange Socket behaviour on Shutdown

Strange Socket behaviour on Shutdown

Scheduled Pinned Locked Moved C#
helpquestioncsharpsysadmin
1 Posts 1 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.
  • P Offline
    P Offline
    Pixinger77
    wrote on last edited by
    #1

    Hi, I have tracked a strange behavior when I close a .NET TCP Socket. I wrote a TCP-Server which listens on port 6000. I now connect with an self written TCP-Client and everything works fine. When I want to disconnect the client from the server I call code like this: public void Disconnect() { if (socket.Connected) socket.Shutdown(SocketShutdown.Both);:~ socket.Close(); socket = null; } When I now run "netstat -a -p tcp" from the commadline I can still see the connection with the state: localhost:6000 -> localhost:6001 = CLOSING_WAIT (translated from german: SCHLIESSEN_WARTEN) localhost:6001 -> localhost:6000 = FIN_WAIT_2 (translated from german: FIN_WARTEN_2) Looks like there are some fragments of the connection still there. By the way... I am not able to create new connection on the same port at this time. Only when I finish my application, the connection between 6000:6001 in "netstat" is gone. The strange thing is, that if I disconnect with the code below, everything works fine. I cant find any connections with "netstat" after the disconnection, and I'm able to create a new connection with the same ports... :confused: Here is the code: public void Disconnect() { //Do NOT shutdown!!! //if (socket.Connected) // socket.Shutdown(SocketShutdown.Both); socket.Close(); socket = null; } So... can someone tell me what is happening here? As far as I know it should be right and neccessary to call socket.Shutdown(...) with the TCP-Protocol. I read a lot of MSDN documentation but couldnt find any clues to this. As far as I tracked the problem, it only appears when I call socket.Shutdown(Socketshutdown.Send). socket.Shutdown(Socketshutdown.Receive) works apperntly fine. Maybe there is some socket coder outside that can help me.;) Thanks in advance, Snow.

    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