server listening to multiple sockets? select() function?

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

server listening to multiple sockets? select() function?

811 次查看
jpa
Contributor IV
I'm trying to implement a TCP socket server that can listen to multiple connections, but all the MQX examples seem to show the server listening to a single connection at a time. Is there a way to structure the code so it's listening for both incoming connection requests and incoming data from already connected sockets? In Linux, I used the select statement, and had it checking both. Should these be separate tasks under MQX? One listening for new connections and spawning new tasks for each socket as it connects? Polling? (Yikes!) John
标签 (1)
标记 (1)
0 项奖励
1 回复

318 次查看
trailman
Contributor V

I guess you can do that in one task by creating one socket per port and use RTCS_selectall() to wait for events on at least one socket and then process them with accept() or recv().

See RTCS User's Guide in BSP source tree : doc/rtcs/MQXRTCSUG.pdf (also downloadable form Freescale's web)

There's some sample code in the doc.