read and write to same socket (TCP) using select

前端 未结 4 456
悲&欢浪女
悲&欢浪女 2020-12-16 18:00

We\'re writing a client and a server to do (what I thought was) pretty simple network communications. Mulitple clients connect to the server which then is supposed to send

4条回答
  •  执笔经年
    2020-12-16 18:23

    I don't see anything wrong with your code, so it should work. If you can't get it working, one way to work around it would be to create a pipe to be used by your reading thread and the thread that prepares things for writing, and add the pipe's reading end to your select set. Then, when the other thread has prepared data to write, it just sends something on the pipe, your reading thread gets woken up from the select, and it can then do the writing. Depending on how often there is data to read or write, this could also be more efficient.

提交回复
热议问题