Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I establish connection between a client and a server where the server sends new messages to the client?

I need to establish connection between a client and a server via PHP websocket.

The server will need to keeps checking with an external API for new messages and send them to the client.

I would like to understand the concept so I can code it. I have some questions to help me wrap it around my head.

The Client Side Do I keep making calls to the server via the websocket every second using javascript's setInterval() function or do I only make one call? How does the client know that the server have new messages?

The Server Side Do I create a script the runs an infinite loop to keep checking with the API and echo the results?

Websocket How does the websocket know which connection a message belong to?

I am not sure if it matter but I am going to use Ratchet for creating the websocket

like image 580
Junior Avatar asked Jan 20 '26 02:01

Junior


1 Answers

On the past days, i solved that problem via Comet. And i used Php,Node.js. You should check comet technology and look up php and NOde.js.

http://www.screenr.com/SNH

http://blog.jamieisaacs.com/2010/08/27/comet-with-nginx-and-jquery/

etc.

like image 181
Muhammet Arslan Avatar answered Jan 21 '26 15:01

Muhammet Arslan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!