开发者

A file server and its associated clients

开发者 https://www.devze.com 2023-03-10 17:34 出处:网络
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 se

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开发者_如何学JAVA 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


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?


I 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 and sftp programs is nice to implement. Have a look at it. http://openssh.org/txt/draft-ietf-secsh-filexfer-02.txt

0

精彩评论

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