为客户端/服务器通信创建命令系统 [英] Create command system for Client/Server communication

查看:61
本文介绍了为客户端/服务器通信创建命令系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在为我开发一个简单的应用程序。我有一个将在服务器中的控制台应用程序,以及将成为客户端的WPF应用程序。我想发送命令,例如/ file create test.txt或/ file delete test.txt

Hello guys. I'm developing a simple app for me. I have a console application that will be in a server, and a WPF Application that will be the client. I want to send commands, for example, /file create test.txt or /file delete test.txt

命令:/ file

和参数可以是:创建,删除,读取,写入

and the arguments can be: create, delete, read, write

如果参数是write,则添加更多参数:/ file write test.text
此行将写入文件

And if the argument is write, add more arguments: /file write test.text This line will be written in the file

此系统还必须在服务器上解释来自客户端的传入消息。该方法也可用于创建游戏。我正确地解释了我?

This system must also be on the server to interpret the incoming message from the client. The method also can be used to create games. I explained me correctly?

Tomas Wegenast

Tomas Wegenast

推荐答案

编写客户端/服务器应用程序有几种不同的方法。这取决于您的要求和性能限制。我可能从Web API开始,因为它是最容易使用的,并且可以使用标准HTTP协议(这意味着
没有防火墙问题)来完成。在您的情况下,您可以拥有一个看起来像这样的API - PUT< url> / files(data = filename),DELETE< url> / files(data = filename)等。

There are several different ways to write client/server apps. It depends upon your requirements and performance constraints. I'd probably start with web API as it is the easiest to work with and can be done using the standard HTTP protocols (which means no firewall issues). In your case you could have an API all that looks like this - PUT <url>/files (data = filename), DELETE <url>/files (data = filename), etc.

列表上的下一个将是WCF。在某些情况下,它可能比Web API更快,并允许更多的客户端。但是,它必须在两侧进行适当配置,并且对于小有效负载的请求/响应通常会有更多开销。另外,如果您使用大型文件,则需要
,然后您必须考虑使用的绑定,以便您可以有效地来回传输文件。

Next up on the list would be WCF. It may be faster than web API in some cases and allows for more disparent clients. However it has to be properly configured on both sides and will generally be more overhead for request/responses for small payloads. Additionally, if you are working with large files then you'll have to consider the binding(s) to use so that you can efficiently transfer files back and forth.

对我来说,最后一个选项是使用原始TCP套接字。这可能是性能最佳的方法,但需要最多的代码。您必须手动构建命令基础结构以及错误处理。它还要求您找到一个使用
的端口,防火墙允许它通过(如果通过网络运行)。除非其他两个选项不可行,否则我不会走这条路。

The last option, to me, is using raw TCP sockets. This is probably the best performant approach but requires the most code. You'll have to build the command infrastructure by hand along with the error handling. It'll also require that you find a port to use and that the firewall allows it through (if running over the network). I wouldn't go this route unless the other 2 options aren't viable.


这篇关于为客户端/服务器通信创建命令系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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