How to call a WebSocket programmatically (using PHP)?

前端 未结 5 2072
孤街浪徒
孤街浪徒 2021-02-04 18:46

I have a situation where I need to update one browser window based on input from the other. Right now I\'m using WebSockets and it\'s working great.

Now I want to sen

5条回答
  •  忘了有多久
    2021-02-04 19:19

    There is a lot more to WebSockets than just sending the raw data to a TCP socket.

    Ok, to start, you're using a UDP socket, where WebSockets use TCP. WebSockets is an entire protocol for communication, similar to HTTP, so you need to follow that protocol, there is a handshake step that you need to perform first and headers you need to add to all communication. It's not difficult, but I'm not going to go into detail here.

    You have two options from here, implement the WebSockets protocol in php, or use a pre-built library like this one: http://code.google.com/p/phpwebsocket/

    I'm not being rude, or mean, but in the future, try a quick Google search. That library I linked was found after googling "PHP WebSockets".

提交回复
热议问题