Some issues with Socket class behavior.
-
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);
ors.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. -
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);
ors.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.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...!
-
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...!
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.