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. Some issues with Socket class behavior.

Some issues with Socket class behavior.

Scheduled Pinned Locked Moved C#
helpquestion
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.
  • J Offline
    J Offline
    Jack045
    wrote on last edited by
    #1

    Hello. Please help me find out if its normal behavior of Socket class. issue#1 - After connecting, first call to Socket.Send always returns immediately. I know that Send puts data in buffer first, but not megabytes, right ? Code: Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s.Connect("61.213.43.1", 30); //Sending returns immediately. //bData can be huge (tested with ~10 mb ) //and bytesSent will always contain bData.Length int bytesSent = s.Send(bData, bData.Length, SocketFlags.None); s.Shutdown(SocketShutdown.Both); s.Close(); This code executes immediately. Including Shutdown & Close. This leads to issue #2: - Socket.Close never blocks (even if MSDN says is should) Code same as above but: s.Close(9999); or s.LingerState = new LingerOption(true, 9999); s.Close(9999); Please confirm such behavior, or suggest what might be wrong and how it works for you. Its very important to me, thank you in advance.

    X 1 Reply Last reply
    0
    • J Jack045

      Hello. Please help me find out if its normal behavior of Socket class. issue#1 - After connecting, first call to Socket.Send always returns immediately. I know that Send puts data in buffer first, but not megabytes, right ? Code: Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s.Connect("61.213.43.1", 30); //Sending returns immediately. //bData can be huge (tested with ~10 mb ) //and bytesSent will always contain bData.Length int bytesSent = s.Send(bData, bData.Length, SocketFlags.None); s.Shutdown(SocketShutdown.Both); s.Close(); This code executes immediately. Including Shutdown & Close. This leads to issue #2: - Socket.Close never blocks (even if MSDN says is should) Code same as above but: s.Close(9999); or s.LingerState = new LingerOption(true, 9999); s.Close(9999); Please confirm such behavior, or suggest what might be wrong and how it works for you. Its very important to me, thank you in advance.

      X Offline
      X Offline
      XeoN Kc
      wrote on last edited by
      #2

      Can you check the following: 1. Do you have a firewall enabled...maybe blocking port 30 on the client or on the server side. 2. Check the return of the Connect() function. 3. Is the client on the same machine as the server?....that will definitely make the sending of data seemless! (you said that bytesSent = bData.Length...therefore the data is being sent somehow...) Well a good thing to do (if you have the server code) is to display the received data to make sure if the data is being received. ____________________________________________________ Come Mutley, we have a race to win...!

      J 1 Reply Last reply
      0
      • X XeoN Kc

        Can you check the following: 1. Do you have a firewall enabled...maybe blocking port 30 on the client or on the server side. 2. Check the return of the Connect() function. 3. Is the client on the same machine as the server?....that will definitely make the sending of data seemless! (you said that bytesSent = bData.Length...therefore the data is being sent somehow...) Well a good thing to do (if you have the server code) is to display the received data to make sure if the data is being received. ____________________________________________________ Come Mutley, we have a race to win...!

        J Offline
        J Offline
        Jack045
        wrote on last edited by
        #3

        Hello XeoN-Kc, thanks for reply. However my problem is not about receiving sent data. And the server application even configured to not receive anything. (on purpose, and its Receive buffer set to 0 ). The point is that independently from how server is functioning, after successful Connect, client's first Socket.Send can "send" data array of any size and return immediately. And second problem is that Socket.Close(n), never waits n seconds, even if there is a lot of data still to be send.

        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