TCP recieve function

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

TCP recieve function

Jump to solution
644 Views
CamiloA_
Contributor III

Hi everybody good afternoon, I have a problem with the recv() function in a TCP/IP application. I need a task that hears all the time if somethig is recieved, so I put this function into an infinite loop, no problem with that. The thing is that I need to continue with my program if nothing is recieved after a period of time, let`s say 1 second for this example. I`ve tried everything and the only way to break out this loop is if I recieve something in my buffer. I`ve tried with all the posible flags (the last argument of the recv function) and nothing works. Furthermore, I have understood that this flags works with UDP sockets an mine is a TCP socket. I thought that a good solution was to create another task that oversees the task where I have my infinite loop, so one task is always listening and the other looking at the data recieved in the buffer. The thing is that in this second new task, once I get to the send() function the program gets lost, it appears to be a pointer, but I don´t know why, It seems that I can only use the send and recieve functions in the main task where I declare the socket and all the connection parameters, Anyone have some info to share with me regarding this issue? Thank you in advanced for your cooperation.


0 Kudos
1 Solution
478 Views
CamiloA_
Contributor III

Thank you very much Don wilson, I will try it, I didnt do this because I already try with the select_all function and nothing happened, I mean it actually worked because the time expired, but never break out the loop. I will try your suggestion though, and see if it works. Best regards and thank you very much.

View solution in original post

0 Kudos
2 Replies
478 Views
obidon
Contributor III

I like the RTCS_selectset function. Setup an array of sockets you are reading from. Call RTCS_selectset passing it the array, the number of sockets in the array, and the time to wait, in a loop. If the result from RTCS_selectset matches a socket you want to read from call recv to get the data.

479 Views
CamiloA_
Contributor III

Thank you very much Don wilson, I will try it, I didnt do this because I already try with the select_all function and nothing happened, I mean it actually worked because the time expired, but never break out the loop. I will try your suggestion though, and see if it works. Best regards and thank you very much.

0 Kudos