Search code examples
javascriptphpsocketstcpnetwork-programming

TCP Server with distants clients


I need to define a way to achieve the following:

TCP Diagram

-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).


Solution

  • 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.