How to call a WebSocket programmatically (using PHP)?

前端 未结 5 2060
孤街浪徒
孤街浪徒 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:21

    In order to send data to the socket, you need to use fsockopen to open the connection to the socket at specified port. If the connection is successfully, all you need to do is use fwrite

    However, you are going to be sending the data to the WebSocket server. The server will treat you as a client, and since you are not providing HTTP headers it expects for successful authentication - your connection will be refused.

    Since you didn't say who is supposed to receive the message you are trying to send (all users or a specific user or something entirely different), without knowing what your goal is - it's hard to explain any further what you should do.

提交回复
热议问题