µTasker Forum

µTasker Forum => NXPTM M522XX, KINETIS and i.MX RT => Topic started by: neil on June 24, 2022, 11:22:06 AM

Title: 1 UDP socket for server and client?
Post by: neil on June 24, 2022, 11:22:06 AM
Hi Mark,
  I have 1 socket setup for UDP server and client, is this okay to do, or am I better having 1 socket as a server and one as sending?   My sequences is as follows:

Create 1 UDP socket and setup a listening routine.

Every 10 seconds:

1. Send a request to the device.
2. It then replies with a result.

Very occasionally the device I am talking to stops responding, even though the commands are sent. If I switch on/off my board it all works again. The way around this is I call "fnReleaseUDP_socket" , then re-initialise it again, and all goes well. But now after a good while I get a hardware fault. I thought it might be a memory issue but cant find anything.

So I am not sure if I have to create a socket for sending, and one for receiving? And if releasing and re-initialising the socket can cause an issue?

Best Regards
Neil
Title: Re: 1 UDP socket for server and client?
Post by: mark on June 24, 2022, 01:45:02 PM
Hi Neil

Only 1 UDP socket is needed.
Transmission can take place at any time on the socket.
The socket call-back is used for reception, which can also happen at any time.

The only thing that changes over time with UDP is related to ARP table entries. If the destination address is in the ARP table transmissions take place immediately and if not ARP first has to resolve it; the cal back informs that the content should be repeated once it has resolved. With time ARP entries time out and this needs to be repeated.

Apart from that detail I don't see that the behavior changes (or failures start occurring) over time so I expect problems are likely to be outside of the UDP functionality.

Regards

Mark

Title: Re: 1 UDP socket for server and client?
Post by: neil on June 24, 2022, 01:58:57 PM
HI Mark,
  Many thanks for your reply.

Best Regards
Neil
Title: Re: 1 UDP socket for server and client?
Post by: neil on June 26, 2022, 05:23:58 PM
Hi Mark
  you have

"The only thing that changes over time with UDP is related to ARP table entries. If the destination address is in the ARP table transmissions take place immediately and if not ARP first has to resolve it; the cal back informs that the content should be repeated once it has resolved. With time ARP entries time out and this needs to be repeated."

Would this involve:
fnDeleteArp();
fnAddARP(ip, mac, ARP_FIXED_IP);

I would know the ip address of the device I am talking to, but is there a way of detecting the mac address after the first connection it makes to the UDP server I have setup in utasker?


Best Regards
Neil
Title: Re: 1 UDP socket for server and client?
Post by: mark on June 29, 2022, 12:50:38 AM
Neil

If you send a UDP packet to an IP address whose MAC is not known it will cause ARP resolution to be started (and not the UDP frame being sent).

ARP informs the owner task, which can then resend the UDP frame when the MAC address is known:

        case TASK_ARP:
            fnRead(PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the message content
            switch (ucInputMessage[0]) {                                 // ARP sends us either ARP resolution success or failed
            case ARP_RESOLUTION_SUCCESS:                                 // IP address has been resolved (repeat UDP frame).
                fnSendUDP(MyUDP_Socket, ucUDP_IP_Address, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
                break;

            case ARP_RESOLUTION_FAILED:                                  // IP address could not be resolved...
                break;
            }
            break;


See also the UDP thread at https://www.utasker.com/forum/index.php?topic=41.0 which explains it in detail.

Regards

Mark
Title: Re: 1 UDP socket for server and client?
Post by: neil on June 29, 2022, 09:50:27 AM
Hi Mark,
   Many thanks for the reply.

Best Regards
Neil