Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I hope someone can help me I have looked and I know very little about websockets. P.S: We are working in a legacy code so it is pure php ( no laravel, symfony, nothing ) We have a partner that our server will have to listen to their websocket (ws://webfeeder.cedrotech.com/ws).

The only example they gave was a client to server ( javascript ) but on our end we will need to keep listening to their websocket and manipulate the data, save it and than write a restapi so that our mobileapp can be updated ( it needs to be updating in real time ).

So I havent' found any example where I can implement a websocket where I will connect and login to their websocket and keep listening so I can make the updates when necessary to the database according to their response. This is their Javascript example but I don't have any idea how to put that in a php form with the needs that we have.

var wsUri = "ws://201.77.219.223/ws";
websocket = new WebSocket(wsUri);

websocket.onopen = function(evt) { console.log("Connected to Endpoint!"); }; websocket.onmessage = function(evt) { console.log("Message Received: " + evt.data); }; websocket.onerror = function(evt) { console.log("ERROR: " + evt.data); }; function doSend(message) { console.log("Message Sent: " + message); websocket.send(message); } doSend('{ "module": "login", "service": "authentication", "parameters": {"login": "test", "password": "123456"}}');



If anyone can help, I would really appreciate it! Thanks!

What I have tried:

I have tried many codes with socket but I am not finding a away to do like my question asks.
Posted
Updated 17-Aug-20 11:04am

1 solution

There are multiple examples on web with PHP/Websocket, please have a look at them:
Simple PHP Chat using WebSocket - Phppot[^]
Create a Bi-directional Connection to a PHP Server using HTML5 WebSockets[^]
PHP and HTML5 WebSocket server and client communication[^]

Try out. If there are gaps, share specific issue with the existing solutions about it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900