Main Site Documentation

Problem when sending data between 2 raptor's through ENC28 module


#1

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!


#2

you have not provide a complete program displaying your issue, so we have to guess as to the cause.

are you calling these methods from ProgramStarted, or an event handler? if so, then this can cause problems.

please post the smallest program(s) that display your problem.


#3

great first post - but as Mike says, we really need a full example app that will help us demonstrate this elsewhere.

This is networking as well - did you run network monitor / wireshark and look at the actual traffic generated? That’s a very simple way to see if you are actually sending, or just not receiving.

Most of these kinds of issues are related to improper handling of network startup, so that’s the area we’ll be looking in your code.


#4

I had a similar problem between devices a year or so ago, and it turned out that I hadn’t assigned unique Mac addresses to each device. (This is definitely important if more than one device in the same local network!). By default, all devices have the same Mac address out of the box.


#5

Thx for the reply!

I have made 2 small test projects. They are both tested on the Raptor - boards and I still receive the problem, so it should be a good example I think.
You can download the solutions from the links below:

And also a picture of the entire project, there are 4 raptor’s that control and interact with the electrical system of my home.

First I try the connection between only 2 devices… and the post of michaelb is interesting, because I have not set a MAC address on each ENC28. I’m going to search how I can set the MAC and wil try again.

I let you know something if that’s the solution to my problem!

Thx!!


#6

In addition to the replay from Superhuman, a screenshot of Wireshark.
This is the only package that has been sent, after 21 minutes waiting.

So the server receive, but he have to wait 21 minutes before you see that the message is transmitted by the client. Immediately after sending by the client, the server also receives correctly the message.


#7

The Mac is set via Fezconfig or MFdeploy, can’t remember at the moment, but can posted later when I get to the office of you’ve not figured it out before. (Neither run on Android to check)…


#8

Solved!

Indeed the de configuration of unique MAC addresses for each ENC28 did the trick! (Through the FEZ Config tool)

Thanks a lot for the assistance!