开发者

How to read data from cin and send on socket while async_accepting from that socket?

I currently have a server using Asio like the example here. Currently, it works as intended in that every packet it receives from the client is responded to by the session::handle_read function.

However, I want to modify the server so that it can also accept data from the command line and send that across the packet t开发者_高级运维o the client (unsolicited by the client) while still listening for input from the client.

I'm not really sure where to start modifying what I have... so pointers there would be helpful. I'm thinking that I need additional work in the session::start function (e.g. read from the command line then use an async_write to write out that data); does that seem logical?


I want to modify the server so that it can also accept data from the command line and send that across the packet to the client

Use a posix::stream_descriptor to read from STDIN_FILENO. See this previous question and answer for a more complete example and solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜