简体   繁体   English

实现简单 HTTP 服务器推送到 C# 客户端的最佳方法

[英]Best way to implement simple HTTP server push to C# client

First of all, my apologies for the most likely inappropriate wording of the question.首先,对于这个问题最可能不恰当的措辞,我深表歉意。 Not knowing exactly how to describe the problem I need to solve has been a major roadblock in my attempts to solve it.不知道如何准确描述我需要解决的问题一直是我尝试解决它的主要障碍。

I currently have a web server (Laravel) that needs to communicate with a SQL server in a different network, which only permits outgoing traffic.我目前有一个 web 服务器(Laravel),它需要与不同网络中的 SQL 服务器通信,它只允许传出流量。 I made it work by having a C# daemon, running inside the SQL server's network, poll it for data and send it to the server through HTTP POST requests.我通过在 SQL 服务器的网络中运行 C# 守护程序使其工作,轮询数据并通过 HTTP POST 请求将其发送到服务器。

However, I now need the web server to communicate with the daemon.但是,我现在需要 web 服务器来与守护进程通信。 Something as simple as:像这样简单的东西:

  1. someone looks up a username on the web server有人在 web 服务器上查找用户名
  2. the server requests the daemon to look it up on the database服务器请求守护进程在数据库中查找它
  3. the daemon returns whatever information it found to the web server.守护程序将它找到的任何信息返回给 web 服务器。

What I'm struggling with is finding the best way to do this.我正在努力寻找最好的方法来做到这一点。

All I need is for the server to be able to push requests to the daemon in real time.我所需要的只是让服务器能够实时将请求推送到守护进程。 The daemon can reply through HTTP POST requests to the server, just like it is doing already.守护进程可以通过 HTTP POST 请求回复服务器,就像它已经在做的那样。 The best potential solution I have found is WebSockets, but it also sound like it might be overkill.我发现的最好的潜在解决方案是 WebSockets,但听起来它也可能有点矫枉过正。

Am I missing something or are WebSockets indeed the way to go?我是否遗漏了什么或者 WebSockets 确实是通往 go 的方式?

Guzzle is what I use to make HTTP requests to external APIs in Laravel. Guzzle是我用来向 Laravel 中的外部 API 发出 HTTP 请求的工具。

Websockets are mostly used when the user has no control over the responses, for example, a chat window. Websocket 主要用于用户无法控制响应的情况,例如聊天 window。 But if you need to, for example, click a button and wait for the response Guzzle is enough.但是,如果您需要,例如,单击一个按钮并等待响应,Guzzle 就足够了。

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

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