Hi everyone,
I have 2 FEZ Raptors with ENC28 module (.NETMF 4.3). They need to send some message to each other, through TCP communication.
They both are connected on a router. But the client raptor can send the message after 21 minutes waiting for some reason and I can’t find why?
I have my code simplified to this, to debug:
The client code:
private void SendMessage(String message)
{
remoteEP = new IPEndPoint(new IPAddress(new byte[] { 192, 168, 1, 2 }), 80);
socket = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_message = "01P00";
byte[] msg = Encoding.UTF8.GetBytes(_message + "<EOF>");
socket.Connect(remoteEP);
socket.Send(msg);
byte[] bytes = new byte[1024];
int bytesRec = socket.Receive(bytes);
socket.Close();
}
The server:
IPEndPoint local = new IPEndPoint(IPAddress.Parse("192.168.1.2"), 80);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(local);
socket.Listen(Int32.MaxValue);
Socket incommingConnection = socket.Accept();
byte[] buffer = new byte[1000];
int bytesReceived = incommingConnection.Receive(buffer);
incommingConnection.Send(Encoding.UTF8.GetBytes("test_ok"));
_console.Print("Bytes received: " + bytesReceived);
When my client sent the message, the server continuous where it was waiting on the “.Accept()” code but it’s waiting then into the “Receive(…)” code.
- At that moment incommingConnection.Available is 0
- When I poll the socket for reading, it is false
- De client did not send the message yet I can see in WhireShark !?!?
- The client code is waiting on the “receive()” code, so it has sent the message and is waiting for the response from the server raptor.
- After 21 minutes approximately, the message is suddenly transmitted by the client and the server can display the message
So it looks like de client socket / hardware is waiting for some reason before start sending.
I have been searching for several days without any result… setting socketoptions, small / bigger buffers, bigger message, …
I discovered only when I send the message to a PC, which is also connected on the same router, (also similar synchronous code on the pc server), the client sent immediately… When I send data from a PC (the same similar synchronous code on the pc client) to the server, also immediately the data is received on the raptor. So sending / receiving data to / from a PC is no problem.
It looks like the code on the raport’s is working great in communication with a pc, but it doesn’t work anymore when they need to communicatie to each other or it takes 21 minutes.
Do you see what I’m missing or did wrong?
What can I try or test?
Thx a lot for any assistance!