Main Site Documentation

Socket.Send not blocking


#1

Hey Guys,

Hopefully someone here can help me out, I’m doing some benchmarking and profiling of Sockets in .Net MF, I have two EMX units ( 1 Spider and 1 Custom Board )

On one board I’m running the Socket server example from the SDK and on another board I have written a test program that does various connects and sends to the other EMX board and a server program running on my pc, I found the Connect doesn’t time out when there is no endpoint which is a common thing everyone knows about but one thing I have that I found that i cant find anything on is that the send appears to be a asynchronous call as if i remove the network cable of the other EMX running the server or stop the Server program running on my PC and then step over the send it always succeeds, even returning correct number of bytes written.

What is stranger is that after pulling the cable out and letting the program still run without closing that socket and then plugging the cable back in I get the data at the other end, but if I disconnect the socket without plugging the cable in I loose the data without any notification to my app.

Has anyone else experienced these types of issues? or anyone know how or if we can change the send to be blocking?


#2

@ TheScruba - You can put the socket.connect (…) in a thread and abort the thread it you want it to timeout. for send and receive you can set the send and receive timeout property of the socket


#3

Hi Andre, this is OK if its the client end that has the disconnect but what if its the server end that drops off?


#4

@ Andre, there is a switch in between all three devices to help explain further here is my setup:

  • EMX acting as a client connecting to the following two devices:
  • EMX running the Sample Server application
  • Windows 7 x64 running a simple socket server.

If I pull the network on the server end I get the CableConnectivityChanged event fired.

My main question really is should the socket send act with the same behaviour as all other socket implementations where it will block on the send to confirm successful transmission of data?

@ RobvanSchelven i set the SendTimeout to 1000 still no luck just stepped straight over and succeeded. also i noticed a variable in the socket class that is called m_fBlocking and thats set to true? not too sure if that has any bearing to sending or just connecting?


#5

@ andre sorry thought I answered everything! :slight_smile: all tests are using TCP sockets


#6

@ andre, ok great I was thinking the same but wanted to see someone’s else perspective on it, I’ll jump over to the .net mf codeplex page and post it as a bug and see what they say

With your suggestion when disconnecting the plug from the client end I get an exception thrown when I attempt the send which is what I would expect error 10050 WSAENETDOWN, so at least it half works I guess :slight_smile:

Socket Connected 00:00:00.0035512
Built-in Ethernet Cable is Disconneced!
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::send [IP: 0000] ####
#### System.Net.Sockets.Socket::Send [IP: 0018] ####
#### System.Net.Sockets.Socket::Send [IP: 0008] ####
#### NetworkProfiling.Program::Main [IP: 0141] ####
#### SocketException ErrorCode = 10050
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10050
#### SocketException ErrorCode = 10050
An unhandled exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll


#7

Ok something even stranger which almost confirms it as a bug is that I thought I would put the send inside a for loop and see if i get a buffer overflow as Andre suggested but as you can see the first send succeeds then the very next one throws and exception with the exception I would expect on the first one 10054 WSAECONNRESET

Resolved Host Address 172.17.0.1 00:00:00.0018532
Socket Connected 00:00:00.0035745
Sent 3 bytes 00:00:11.9468850
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::send [IP: 0000] ####
#### System.Net.Sockets.Socket::Send [IP: 0018] ####
#### System.Net.Sockets.Socket::Send [IP: 0008] ####
#### NetworkProfiling.Program::Main [IP: 0147] ####
#### SocketException ErrorCode = 10054
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10054
#### SocketException ErrorCode = 10054
An unhandled exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll


#8

@ Andre, both the exceptions are generated from the client, the first one was generated when I removed the network cable from the Client before the send and it threw the 10050 WSAENETDOWN exception

The other one was generated when I put the send in a loop and stop the server program on my pc, the first send succeed but the very next send generated the 10054 WSAECONNRESET exception


#9

Hey Guys,

Have created the issue over at the .net mf codeplex page so if anyone is wanting to follow it here is the link.

Now to start working up the layers to HTTP!

Thanks andre for your advice.