多线程套接字服务器与非阻塞套接字服务器? [英] Difference between Multi-threaded socket server & Non-blocking socket server?

查看:94
本文介绍了多线程套接字服务器与非阻塞套接字服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我现在正在为我的应用程序的通信编程套接字服务器.我希望我的线程模式实现一个服务器,该服务器可以同时允许多个请求(而不是像顺序队列那样等待).我也遇到过Blocking属性.两者有什么不同?

谢谢!

Hello everyone,

I''m now programming a socket server for my applications'' communications. I want my threading pattern to implement a server that can allow multiple requests at the same time (not waiting as a sequential queue does). I''ve come across the Blocking property too. What''s different between these two?

Thanks!

推荐答案

从根本上说,多线程套接字服务器与非阻塞套接字服务器之间的区别非常微妙.

在这两种情况下,都涉及多线程.主要区别在于对请求的处理.

在多线程服务器中,一旦收到请求,其余的操作(包括从传输数据到处理的所有内容)将被扔到另一个线程,该线程从那里获取并处理所有工作,最后关闭连接(希望以一种优美的方式).

非阻塞服务器具有一个在端口上侦听的线程,并在发出请求时将特定任务委派给后台"线程,以便该线程的操作可以继续进行,并且不会因长时间运行而被阻塞(可能失败)功能.

足够解释了吗?
Primarily, the difference between a multithreaded socket server and a non-blocking is pretty subtle.

In both cases, multi-threading is involved. The main difference lies in the handling of the request.

In a Multi-threaded server, once a request is received, the rest of the operation(s) which include everything from transferring data to processing is then thrown to another thread which takes it from there and handles all of the work and finally closes the connection (hopefully in a graceful manner).

A non-blocking server has one thread that listens on the port and when a request is made it then delegates a specific task to a "background" thread so that operation of that thread can continue and not be blocked by a long running (possibly failing) function.

Did that explain it well enough?


这篇关于多线程套接字服务器与非阻塞套接字服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆