文件服务器及其关联的客户端
我对套接字编程非常陌生,我正在实现一个文件服务器,它接收来自客户端的 open()、read()、write()、close() 等请求。文件服务器将处理请求并向客户端发送每个系统调用的返回值。
我不知道需要定义什么类型的套接字(即流套接字、数据报套接字等)。客户端将使用什么命令发送请求,我将如何从服务器接收返回值,我将如何在服务器端接收它并将返回值发送到我的客户端。
如果能得到一些指点,我将不胜感激。
谢谢
编辑:像这样的简单工作可以启动 服务器无法正确读取/打开 C 中客户端发送的文件名
I am extremely new to socket programming and I am implementaing a file server that receives request like open(), read(), write(), close() from clients. The file server will process the requests and send the clients the return value of each system call.
I don't know what type of socket I need to define(i.e. stream socket, datagram socket etc). and what command will send the request from the client, how will I receive the return value from the server, how will I receive it at the server end and send the return value to my client.
Will be gratefull to get some pointers.
Thanks
An edit: Is something simple like this work for starting Server not able to properly read/open a filename sent by client in C
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这部分取决于您的文件服务器设计。
如果您要使用无状态服务器,那么数据报或流就可以了。数据报相对较好,因为您的服务器和客户端不需要处理部分请求——请求的全部内容都包含在数据报中。
如果您要使用有状态服务器,那么流可能会更好 - 您可以自动释放当您收到 TCP
RST
数据包时,锁定并取消分配客户端“拥有”的资源。 (客户端消失了,扔掉它们的状态。)当然,您可以使用数据报服务构建有状态服务器,但这似乎不太合适。但在开放的互联网上,通常只有 UDP 和 TCP -- 我不知道是否 RDP 是一种可靠的数据报传输,可以在给定的 ISP 上路由,也可以不路由。由于被迫在不可靠数据报和可靠流之间,我几乎每次都会推荐可靠流。您只会在可靠的 LAN 上使用您的协议吗?或者在有损无线或公共互联网链接上?
It depends in part upon your file server design.
If you're going for a stateless server, then datagram or stream would be fine. Datagram is relatively nice because your servers and clients don't need to handle partial requests -- the entire contents of the request are contained in the datagram.
If you're going for a stateful server, then stream might be nicer -- you can automatically release locks and de-allocate resources 'owned' by a client when you receive a TCP
RST
packet. (Client gone, throw away their state.) You could of course build a stateful server with datagram services, but it doesn't seem like a good fit.But on the open Internet, typically you have just UDP and TCP -- I have no idea if RDP, a reliable datagram transport, is routed on given ISPs or not. And being forced between unreliable datagrams and reliable streams, I'd recommend reliable streams almost every time. Will your use your protocol on reliable LANs only? Or on lossy wireless or public Internet links?
我会使用流式套接字,但其他人的做法有所不同,例如网络文件系统(NFS)。
要在客户端和服务器之间进行通信,您需要一个协议。 OpenSSH 用于其
scp
和sftp
程序的方案很容易实现。看看吧。 http://openssh.org/txt/draft-ietf-secsh-filexfer -02.txtI would use a streaming socket, but others have done differently, for example the Network File System (NFS).
To communicate between a client and the server you need a protocol. The one that OpenSSH uses for their
scp
andsftp
programs is nice to implement. Have a look at it. http://openssh.org/txt/draft-ietf-secsh-filexfer-02.txt