In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to realize the interaction between the web page and the remote server TCP by PHP". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how PHP can interact with the remote server TCP.
Recently participated in an Internet of things project, scenario: there are multiple devices connected to the server through tcp, requiring customers to remotely use web pages to manage the device. The web page does not directly control the hardware, but treats the server as a transit station. The web page sends instructions to the server, and the server sends these instructions to the corresponding device, and vice versa, the device sends the instructions to the server, and the server pushes the device instructions to the web page.
The author is responsible for the interaction between the web end and the remote server. Because the transmission of instructions needs to be fast and real-time, the basic framework chosen by the author is php+socket+redis. After two days, the basic process has been implemented, and the web side and the server have achieved real-time interaction. Let's write down the basic ideas, hoping to play a role in attracting jade.
Implementation plan:
1. The web end interacts with the PHP background through websocket
2. Swoole or workerman can be used in the background. I use workerman here.
3. Store the instructions received on the web page into the cache (client key). The cache can be cached locally or redis at about the same speed. Redis is selected here for easy use of queues and future upgrades)
4. Cache the client value and transfer it to the remote server (socket_write) through the php extension socket
5. Receive instructions from the remote server (socket_read) and store them in the cache (server key)
6. Transfer the cached server value, that is, the instruction of the remote server, to the web side.
7. the reverse is the same, the instructions from the remote server can be immediately pushed to the web side
In addition, I saw a basic idea of using PHP to directly operate the hardware serial port on the web page: the implementation scheme:
1. The web end interacts with the php background service through websocket
2.php background receives instructions to operate serial port and sends hexadecimal instructions to hardware devices.
The 3.php background passes the return value of the hardware device to the web end through websocket.
4. The web side receives the push message and displays it on the page.
At this point, I believe that everyone has a deeper understanding of "how to realize the interaction between web pages and remote server TCP by PHP". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.