简体   繁体   English

ASP.NET和TCP服务器解决方案

[英]ASP.NET & TCP Server Solution

My server has two applications running on it: 我的服务器上运行了两个应用程序:

  1. TCP socket server that continuously accepts and sends messages to and from clients (C# .NET Winforms) 连续接受客户端和从客户端发送消息的TCP套接字服务器(C#.NET Winforms)
  2. ASP.NET application ASP.NET应用程序

What I need is: 我需要的是:

  • When a message is received from a client via the TCP connection (app 1) I want the ASP .NET application (app 2) to reflect this data dynamically. 当通过TCP连接(app 1)从客户端收到消息时,我希望ASP .NET应用程序(app 2)动态地反映这些数据。 I realise that I can set database entries via the TCP socket, which will then be picked up by the ASP.NET application. 我意识到我可以通过TCP套接字设置数据库条目,然后由ASP.NET应用程序接收。
  • A way of sending messages to clients from the ASP .NET application to clients that are available inside of the TCP socket server 一种向客户端发送消息的方法,从ASP .NET应用程序到TCP套接字服务器内部可用的客户端

eg A simple chat program where a client sends “Hi” and server responds “Welcome” . 例如,一个简单的聊天程序,客户端发送“Hi” ,服务器响应“Welcome” The ASP .NET should show a log of this conversation as it happens. ASP .NET应该显示此对话的日志。 Immediately. 立即。 And if I click a button on the ASP application, it should send a message on behalf of the socket server to the client “You have been accepted onto the server” 如果我单击ASP应用程序上的按钮,它应该代表套接字服务器向客户端发送消息“您已被接受到服务器上”

For the most part, the messages are going to be fairly short like the ones shown here. 在大多数情况下,消息将像这里显示的那样短。

What is the best way to do A and B? 做A和B的最佳方法是什么?

if your "messages" are mostly textual, you may want to take a look at SignalR . 如果您的“消息”主要是文本消息,您可能需要查看SignalR

SignalR is a new library for asp.net to enable real-time web functionality. SignalR是asp.net的新库,用于启用实时Web功能。

It uses websockets (or long polling if websockets is unavailable at server/client). 它使用websockets(如果websockets在服务器/客户端不可用,则使用长轮询)。

It has support for different client types. 它支持不同的客户端类型。

SignlaR is a good solution if you're getting the messages from another SignalR client (web page). 如果您从另一个SignalR客户端(网页)获取消息,SignlaR是一个很好的解决方案。

But what if these messages are being sent from a 3rd system over TCP/IP? 但是如果这些消息是通过TCP / IP从第三个系统发送的呢? Then you need to open a TCP port in the ASP.NET Web Application and after receiving a message you have to push it to the web clients. 然后,您需要在ASP.NET Web应用程序中打开TCP端口,并在收到消息后将其推送到Web客户端。

But the question is, what is the best way to have such a TCP Listener hosted in a Web Application (ASP.NET)? 但问题是,在Web应用程序(ASP.NET)中托管这样的TCP侦听器的最佳方法是什么?

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

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