简体   繁体   English

简单快速地在C#中实现套接字服务器

[英]Simple and quick to implement socket server in C#

I have a C# command line app (the server), that is executed by another app (the client). 我有一个C#命令行应用程序(服务器),由另一个应用程序(客户端)执行。 It simply does a command and shuts down. 它只是执行命令并关闭。 I'm trying to convert this "run and shut" method to a "constantly running" windows forms. 我正在尝试将此“运行和关闭”方法转换为“恒定运行”的Windows窗体。 I'll use sockets as a way for the client app to talk to the server in C#. 我将使用套接字作为客户端应用程序与C#中的服务器进行通信的一种方式。 My client app can talk in sockets, but I need a quick and simple way to integrate socket server functionality in C#. 我的客户端应用程序可以通过套接字进行通信,但是我需要一种快速简单的方法来在C#中集成套接字服务器功能。

I've tried to work with the following, but they all seem overly complex to integrate. 我已经尝试使用以下方法,但是它们似乎集成起来都过于复杂。 Do you have any idea how to use these effectively, or any simple socket server component in C#? 您是否知道如何有效地使用它们,或者C#中的任何简单套接字服务器组件?

These seem quite robust, but complex: 这些看起来很健壮,但是很复杂:

These seem quite promising (no idea how limited/functional they are): 这些似乎很有希望(不知道它们的功能/功能如何):

They may seem complex but the ASync Socket stuff isn't too bad and there are lots of examples on how to implement it. 它们可能看起来很复杂,但是ASync Socket的内容还不错,并且有很多有关如何实现它的示例。 Being Asynchronous makes it easy to handle multiple connections simultaneously so I'd recommend having another look at it. 异步使您可以轻松地同时处理多个连接,因此我建议您再来看一遍。

I've not used it myself but the TCPListener Class looks simpler to implement and comes with some examples on it's use. 我自己没有使用过它,但是TCPListener类看起来更易于实现,并且附带了一些使用示例。

如果您正在寻找可以轻松地使服务器和客户端相互通信的内容 ,请访问networkComms.net ,尤其是在此处演示最基本功能的简短示例,希望它不会过于复杂!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM