TCP IP服务器可以处理多个请求吗?
我正在学习 TCP/IP 并尝试使用它在我的服务器上执行不同的命令。
我想我应该从小事做起,逐步积累。我正在运行一个当前示例,其中有服务器和客户端连接,然后服务器将当前时间发送到客户端。
现在我想让服务器可以处理多个客户端。
我该怎么做?我想我可以使用 fork,但是有没有办法在不用担心多个进程的情况下做到这一点?
关于此类事情有什么好的入门知识吗?或者您可以提供一些有关如何修改我现有代码的说明吗?
谢谢,
I'm learning about TCP/IP and am trying to use it to execute different commands on my server.
I thought i'd start small and build up. I've got a current example running which has a server and client connect, and then the server sends the current time to the client.
Now i want to make it such that the server can handle multiple clients.
How can I do this? I think i could use fork, but is there a way to do it without having multiple processes to worry about?
Are there any good primers on this sort of thing, or could you provide some instructions on how to modify my existing code?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
glibc 手册 有一个很好的例子。缺失的代码位可以在本章前面找到。该示例的好处是您不需要多个线程
glibc Manual has a nice example. The missing code bits can be found earlier in the chapter. The nice thing about the example is that you do not need multiple threads
我建议使用线程:
select
函数允许一个线程处理多个套接字。我不知道我的头顶上有什么底漆,抱歉。
I would recommend the use of threads:
select
function to allow one thread to handle multiple sockets.I don't know any primers off the top of my head, sorry.
看看 Erik 对另一个问题的回答。您实际上不需要进行多线程处理。
Take a look at Erik's answer on this other question. You don't really need to do multithreading.