TCP服务器与远程客户端

huangapple go评论77阅读模式
英文:

TCP Server with distants clients

问题

我需要定义一种实现以下目标的方式:

TCP服务器与远程客户端

  • 用户将在终端上浏览网页(带有按钮、字段等...)

  • 不同地方会有几个这样的终端(不在同一个本地网络中)

  • 当用户与这些终端进行交互时,将向TCP服务器发送订单

  • 根据负责订单的终端,TCP服务器必须向另一侧的相应TCP客户端发送命令。

  • 在另一侧接收数据的终端是配置为TCP客户端的Android终端(在另一种配置中已经开发并运行)

目标是避免从每个终端轮询服务器以了解它们是否必须执行某些操作。

我的问题是:

实现这一目标的最佳结构方法是什么?

我尝试过查看这些解决方案:

  • 使用纯PHP开发TCP服务器/客户端。

  • 使用JS和Node JS,但我无法弄清楚如何在HTML页面中使其工作

无论如何,如何才能拥有一个“永远”监听的TCP服务器,准备好接听客户端并向它们发送数据呢?如果我在几个终端上打开我的网页并再次创建套接字,它会取代之前创建的吗?

我在这个领域确实缺乏很多东西,会很感激一些引导(不需要完整的解决方案,因为我总是尝试自己学习)。

英文:

I need to define a way to achieve the following:

TCP服务器与远程客户端

-Users will be browsing a Web Page on a terminal (with buttons, fields, etc...)

-There will be several of these terminals at different places (not in the same local network)

-When users interact with these terminals, orders will be sent to a TCP Server

-According to the terminal that is responsible of the order, TCP Server must send a command to the corresponding TCP Client on the other side.

-The terminals receiving data on the other side are Android terminal configured as TCP Client (part already developped and working in another configuration)

The goal is to avoid polling the server from each terminal to know if they must execute something.

My Question:

What would be the best structural approach to achieve this?

I tried to look at these solutions:

-Pure PHP TCP Server/Client developpment.

-JS with Node JS but i can't figure out how to make it work with HTML pages

In any case, what would be the way to have an 'Ever' listening TCP Server ready to listen to clients and send data to them? If i open my web pages on several terminals and create the socket again, it will replace the previously created one?

I really lack a lot of things regarding this domain and would appreciate leadings (no full solutions required as i always try to learn by myself).

答案1

得分: 1

你应该查看诸如 Socket.IOgRPC 这样的技术。

REST API 将通过生成请求、将请求发送到服务器并等待答复来工作。
假设服务器是被动的,等待请求来响应。

例如,使用 Socket.IO,客户端和服务器之间存在一个 连接,服务器可以通知客户端。

英文:

You should take a look at technologies like Socket.IO or gRPC.

REST API will work generating a request, sending the request to the server and waiting for an answer.
Let's say that the server is passive and waiting for requests to answer.

With Socket.IO for example, there is a link between client and server and server can notify the client.

huangapple
  • 本文由 发表于 2023年5月22日 21:53:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76306908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定