Receive UDP frame on a socket while another socket is in TCP listen state?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Receive UDP frame on a socket while another socket is in TCP listen state?

Jump to solution
2,134 Views
arnogir
Senior Contributor II

Hello

I have ask this question in other post but with an other, then this second question was not answered.

I post it to separate the subject.

(MQX Ethernet: Send UDP Frame? )

I use K60 with MQX 4.2 and KDS 3.0.0.

My system need to communicate with a laptop (where I developing my own software) with UDP Frame (Send / Receive)

This is done in one MQX task.

In the same time, the K60 should use another socket (TCP) set in listen state by Calling Listen and then accept.

This other part is done in one OTHER MQX task.

I know the accept function is blocant until link is done.

During this time, the other task which manage UDP frame is always working.

But while "accept" not return because no connection on TCP, the UDP frame cannot be received. Function recvfrom() failed with error 1704

Please could you help me on this point?

:smileyhappy:

0 Kudos
1 Solution
1,255 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Arnaud,

I was able to recreate the issue. It looks like the RTCS_selectall() is also reading the activities in the TCP socket. You need to isolate the sockets that are only for UPD server. Please use RTCS_selectset() instead. I am adding an example code that I tested and worked. Now both TCP and UDP servers are working as expected when using RTCS_selectall().

Hope this helps you.


Have a great day,
Garabo

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
15 Replies
1,255 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Arnaud,

The 0x1704 error means that the socket is invalid:

#define RTCSERR_SOCK_INVALID     (RTCS_ERROR_BASE|0x704)

Are you sure you are creating enough sockets? Do you have something like this in your code before calling the RTCS_create() function?:

_RTCSPCB_init = 4;
_RTCSPCB_grow = 2;
_RTCSPCB_max = 8;

Have a great day,
Garabo

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Hello

I have only this:

  _RTCSPCB_init = 6;

  _RTCS_msgpool_init
= 6;

  _RTCS_socket_part_init
= 6;

But default value are defines by MQX:

RTCSCFG_PCBS_INIT     #define RTCSCFG_PCBS_INIT 10 #endif

RTCSCFG_PCBS_GROW    #define RTCSCFG_PCBS_GROW 0 #endif

RTCSCFG_PCBS_MAX    #define RTCSCFG_PCBS_MAX RTCSCFG_PCBS_INIT   ( = 10) #endif




So it is like if I was:

_RTCSPCB_init = 10
_RTCSPCB_grow = 0
_RTCSPCB_max = 10;


If theses values explain my problem? Then I will test with your value.

0 Kudos
1,255 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Arnaud,

You have 6 and that should be enough for the 1 TCP and 1 UDP connections. Please share the screenshots that the task aware debugging is getting from the memory, task usage, task status and any other that could be showing an error.


Have a great day,
Garabo

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Hello

Anybody Can help me according debugging information provided above?

Or are they an existing example which use a socket in TCP while use another in UDP? (UDP working when TCP is in listen) ??:smileyblush:

0 Kudos
1,256 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Arnaud,

I was able to recreate the issue. It looks like the RTCS_selectall() is also reading the activities in the TCP socket. You need to isolate the sockets that are only for UPD server. Please use RTCS_selectset() instead. I am adding an example code that I tested and worked. Now both TCP and UDP servers are working as expected when using RTCS_selectall().

Hope this helps you.


Have a great day,
Garabo

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Hello

I have another effect:

I can't send message on UDP socket while try to obtain IP address on DHCP or without a bind static IP.

It is really a problem for me. I think a Real ethernet could work on UDP without any assigned IP address.

Are they a way to use UDP without need to configure an IP address? or during a DHCP request (ipcfg_bind_dhcp_wait)

Arnaud

0 Kudos
1,255 Views
Martin_
NXP Employee
NXP Employee

UDP

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Like indicated by "Vines" in the linked post:

Now I can send UDP messages even though I am not binded. It is a bit messy because I need to recreate all struct definitions and pointers as it is being handled by RTCS which is private to my application. As you mentioned these functions were not meant to be used in the application layer.

Then, I can not recreate the adequate structures to properly use the famous API "IP_route_add_direct". So could you help me for this?

I think this function should be called in stead of actual bind.?

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Anybody can indicate to me how use this API?

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Hello

I seen this post.

I already tried the provided solution but I did not get to make it work properly.

The post is not very clear: I don't know If I called  IP_route_add_direct with the good parameters and in the good position order. (before/after Create or socket or bind or...)

:smileyblush:

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Ok

Thank for your investigations.

Let me try in a day and II will back to you.

Thank you:smileyhappy:

Edit: All work correctly now.

Thank for your help!:smileywink:

0 Kudos
1,255 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

HI Arnaud,

Let me try to create an example. I will keep you updated.

Have a great day,
Garabo

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Thank you for your involvement:smileyhappy:

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Hello

Then I provide to you my main file which include both task EthTcp and EthUdp which call main function in the "DV_Eth.c" file.

Each of them start and configure the need to open a socket on UDP and other in Tcp.

Bellow is the trace than optain with the code:

Device intialized on MAC Address 0.0.5E.0.0.0

Waiting for ethernet cable plug in ... Cable connected

Static IP bind ...
08:54:46.088 [RX] - Successful!

IP Address      : 192.168.1.125
Subnet Address  : 255.255.255.0
Gateway Address : 0.0.0.0
DNS Address    : 0.0.0.0

08:54:47.098 [RX] - Init Rx UDP server...

08:54:48.103 [RX] - Init Tx UDP server...

08:54:48.593 [RX] - Wait Ethernet TCP connexion...

08:54:49.108 [RX] -
recvfrom() failed with error 1704
08:54:50.113 [RX] -
recvfrom() failed with error 1704
08:54:51.118 [RX] -
recvfrom() failed with error 1704
08:54:52.123 [RX] -
recvfrom() failed with error 1704
08:54:53.128 [RX] -
recvfrom() failed with error 1704

If I make  a debbuger pause, I obtain following:

Error.png

If UDP frame sent, no receive is OK. But data are weel keep because as soon as TCP connection will accepted, UDS sent data while TCP connecting will get!:

Waiting for ethernet cable plug in ... Cable connected

Static IP bind ...
09:15:35.767 [RX] - Successful!

IP Address      : 192.168.1.125
Subnet Address  : 255.255.255.0
Gateway Address : 0.0.0.0
DNS Address     : 0.0.0.0

09:15:36.776 [RX] - Init Rx UDP se
09:15:36.799 [RX] - rver...

09:15:37.782 [RX] - Init Tx UDP server...

09:15:38.272 [RX] - Wait Ethernet TCP connexion...

09:15:38.787 [RX] -
recvfrom() failed with error 1704
09:15:39.792 [RX] -
recvfrom() failed with error 1704
09:15:40.797 [RX] -
recvfrom() failed with error 1704
09:15:41.802 [RX] -
recvfrom() failed with error 1704
09:15:42.807 [RX] -
recvfrom() failed with error 1704
09:15:43.812 [RX] -
recvfrom() failed with error 1704
09:15:44.817 [RX] -
recvfrom() failed with error 1704
09:15:45.822 [RX] -
recvfrom() failed with error 1704
09:15:46.827 [RX] -
recvfrom() failed with error 1704
09:15:47.832 [RX] -
recvfrom() failed with error 1704
09:15:48.837 [RX] -                                                 ->>>>>>>>>>>>> UDP data send from Computer with "PacketSender" software
recvfrom() failed with error 1704
09:15:49.842 [RX] -
recvfrom() failed with error 1704                          ->>>>>>>>>>>>> UDP data send from Computer with "PacketSender" software
09:15:50.847 [RX] -
recvfrom() failed with error 1704
09:15:51.852 [RX] -
recvfrom() failed with error 1704
09:16:01.711 [RX] -
recvfrom() failed with error 1704
09:16:02.716 [RX] -
recvfrom() failed with error 1704
09:16:03.721 [RX] -
recvfrom() failed with error 1704
09:16:04.241 [RX] -
Connection TCP from 192.168.1.122, port 63133 at socket 0x1fff9a90                ------------------->>>>> DockLight connection on TCP port done....

09:16:04.726 [RX] -
Received 4 bytes of data.Data received: , Packet 1                                               -------------------->>>> previous Sent UDP data are received now!!!!!!!!!
--------SendTO Return = 10

09:16:05.731 [RX] -
Received 4 bytes of data.Data received: , Packet 2                                                  -------------------->>>> previous Sent UDP data are received now!!!!!!!!!
--------SendTO Return = 10

09:16:06.746 [RX] - TimeOut expired. No data received. Trying again

09:16:07.761 [RX] - TimeOut expired. No data received. Trying again

09:16:08.771 [RX] - TimeOut expired. No data received. Trying again

09:16:09.785 [RX] - TimeOut expired. No data received. Trying again

09:16:17.778 [RX] - TimeOut expired. No data received. Trying again

09:16:18.793 [RX] - TimeOut expired. No data received. Trying again

09:16:19.802 [RX] - TimeOut expired. No data received. Trying again

09:16:20.809 [RX] -
Received 4 bytes of data.Data received: , Packet 3                                                 -------------------->>>>New UDP data send from computer and then well received since TCP Ok !!
--------SendTO Return = 10

09:16:21.823 [RX] - TimeOut expired. No data received. Trying again

09:16:22.833 [RX] - TimeOut expired. No data received. Trying again

09:16:23.838 [RX] -
Received 4 bytes of data.Data received: , Packet 4
--------SendTO Return = 10                                                                                        -------------------->>>>New UDP data send from computer and then well received since TCP Ok !!

09:16:24.853 [RX] - TimeOut expired. No data received. Trying again

09:16:25.863 [RX] - TimeOut expired. No data received. Trying again

09:16:42.047 [RX] - TimeOut expired. No data received. Trying again

09:16:43.057 [RX] - TimeOut expired. No data received. Trying again

09:16:44.072 [RX] - TimeOut expired. No data received. Trying again

Note: DV_EthUdp task has always the same error code but all works correctly....

Now, Both UDP and TCP message are well received/sent

------------------ To compare : ------------------

Test when TCP task is not started:

Device intialized on MAC Address 0.0.5E.0.0.0

Waiting for ethernet cable plug in ... Cable connected

Static IP bind ...
09:12:23.359 [RX] - Successful!

IP Address      : 192.168.1.125
Subnet Address  : 255.255.255.0
Gateway Address : 0.0.0.0
DNS Address     : 0.0.0.0

09:12:24.368 [RX] - Init Rx UDP server...

09:12:25.373 [RX] - Init Tx UDP server...

09:12:26.388 [RX] - TimeOut expired. No data received. Trying again

09:12:27.403 [RX] - TimeOut expired. No data received. Trying again

09:12:28.418 [RX] - TimeOut expired. No data received. Trying again

09:12:29.424 [RX] -
Received 4 bytes of data.Data received: , Packet 1          ------> Here UDP frame was sent with "PacketSender software"
--------SendTO Return = 10                                               ------> Here board make a response and is well received by "PacketSender"

09:12:30.438 [RX] - TimeOut expired. No data received. Trying again

09:12:31.453 [RX] - TimeOut expired. No data received. Trying again

09:12:32.468 [RX] - TimeOut expired. No data received. Trying again

If I make debug pause, No error appears in UDP task...

Add:

After investiguation, error is set in function in sock_select.c

uint32_t sock_fds_poll(rtcs_fd_set * fds_ptr, uint32_t size, int32_t checkwhat, int32_t *error)

In this part :

RTCS_FD_ZERO(fds_ptr);

    if(SOCK_ACT_TYPE_CLOSE == activity_type)

    {

      *error = RTCSERR_SOCK_ESHUTDOWN;

      RTCS_FD_SET(closed_sock, fds_ptr);

    }

0 Kudos
1,255 Views
arnogir
Senior Contributor II

Ok

I will try to working on before the end of this week end back to you

Thank for your help

0 Kudos