TCP recieve function

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

TCP recieve function

跳至解决方案
657 次查看
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 项奖励
1 解答
491 次查看
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 项奖励
2 回复数
491 次查看
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.

492 次查看
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 项奖励