使用多个线程的套接字服务器或文件服务器实现:概念尚不清楚 [英] Socket server or file server implementation using multiple threads: concept not clear

查看:136
本文介绍了使用多个线程的套接字服务器或文件服务器实现:概念尚不清楚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我清除这个概念.假设我们有一个使用线程实现的套接字端口服务器.套接字服务器侦听套接字端口,并在消息到达时创建一个线程来处理请求.

Please help me clear this concept. Say we have A socket port server implemented using threads. The socket server listens on a socket port and, when a message arrives, create a thread to service the request.

客户端代码将给定数量的消息发送到服务器.该客户端代码也可以由多个用户在不同的计算机上运行.我知道客户端代码是作为单独的进程运行的.也就是说,单独的进程向服务器发出请求,然后由服务器线程对其进行处理.

The client code sends a given number of messages to the server. This client code could also be run from different machines by multiple users. I understand that the client code codes are run as seperate processes.Ihat is seperate processes issue requests to the server which is then processed by a server thread.

因此,客户端进程堆栈,用户地址空间,进程控制块等是否传递给处理其请求的服务器线程.

So, does a client processes stack, user address space, process control block etc pass on to the server thread that processes its request.

同样,如果它是文件服务器,并且文件打开请求是由服务器线程实现的,则fd是服务器文件描述符表或调用进程的一部分.

Similarly, if it is a file server and a file open request is implemeted by a server thread, then is the fd a part of server file descriptor table or the calling processes.

很高兴获得我可以阅读的材料的任何链接. 谢谢

Would be graatefull to get any link to materials I can read up. Thanks

推荐答案

不,客户端和服务器是不同的进程,甚至可能在不同的计算机上运行.

No, the client and the server are different processes, possibly even running on different machines.

客户端将要求操作系统(通过库)将网络消息发送到服务器,服务器的操作系统将解压缩它们并将它们(通过库)定向到服务器进程.

Clients will ask the operating system (through the libraries) to send network messages to servers, whose operating system will unpack them and direct them (through the libraries) into the server process.

现在客户端处理线程"是另一回事,它们是服务器进程的子组件,在您的设置中,其中一个线程(一个在网络另一端处理客户端的线程)将接收数据并做任何需要的事情(如有必要,可以包括回复).

Now "client handling threads" are a different thing, they are subcomponents of the server process, and in your setup, one of those threads (the one handling the client on the other side of the network) will receive the data and do whatever is needed (possibly including a reply, if necessary).

在文件服务器情况下,操作系统提供的文件描述符永远不会离开"文件服务器.文件服务器客户端创建它们所需的任何内容以镜像远程计算机的内容.这样的镜像可能包括文件描述符,但是它们肯定与服务器上的文件描述符不同.客户端文件描述符绑定到执行请求的操作并将其转换为网络调用的代码,而服务器文件描述符(可能)直接访问磁盘上的块.

In the file server situation, the file descriptor provided by the operating system never "leaves" the file server. The file server clients create whatever they need to mirror the contents of the remote machine. Such mirroring might include file descriptors, but they are definitely not the same file descriptors as those that reside on the server. The client file descriptors are bound to code which takes the requested operation and turns it into a network call, while the server file descriptors (likely) access the blocks on disk directly.

这篇关于使用多个线程的套接字服务器或文件服务器实现:概念尚不清楚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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