I wrote a socket server in php, and after Firefox successfully handshakes the client, 1. use the send () function to send messages to the server. server socket _ read extract information 3. you can use socket _ write to return information to trigger the onmessage event of the client. In ie and... I wrote a socket server in php, and after Firefox successfully handshakes the client,
1. Use the send () function to send messages to the server.
2. server socket _ read extract information
3. Use socket _ write to return information to trigger the onmessage event of the client.
However, in ie and chrome, The onmessage event cannot be triggered,
1. First send () sends the information to the server
2. socket _ select obtains socket A and socket _ read to obtain information.
3. Use socket _ write to return the same information to socket A, and then listen to socket A. It will end in Firefox.
However, in ie, socket _ select will obtain socket A again, and then repeat and return information to listen to socket. Of course, socket _ select will still obtain socket A. After the first two reads and writes, the information obtained by socket _ read will be null.
By the way, in ie, the first time the server executes socket _ write, the return value is int (10). This is normal, and the second write operation returns int (32 ), because the php file is run in cmd, the information obtained by socket _ read is garbled (the handshake protocol is normal ), so I don't know what the information returned by the second socket _ write operation is.
Why? Obviously, the handshakes can be successful. The onopen event has been triggered. Why is there a problem when it comes to onmessage!
If the problem cannot be found based on the above information, the following is my code:
Html:
testSend《script》socket=new WebSocket("ws://localhost:1199");socket.onopen=function(){document.querySelector("#p").innerHTML="ws";}socket.onmessage=function(e){document.querySelector("#p").innerHTML=e.data;}function send(){socket.send("test");}《script》
Php:
Reply content:
I wrote a socket server in php, and after Firefox successfully handshakes the client,
1. Use the send () function to send messages to the server.
2. server socket _ read extract information
3. Use socket _ write to return information to trigger the onmessage event of the client.
However, in ie and chrome, The onmessage event cannot be triggered,
1. First send () sends the information to the server
2. socket _ select obtains socket A and socket _ read to obtain information.
3. Use socket _ write to return the same information to socket A, and then listen to socket A. It will end in Firefox.
However, in ie, socket _ select will obtain socket A again, and then repeat and return information to listen to socket. Of course, socket _ select will still obtain socket A. After the first two reads and writes, the information obtained by socket _ read will be null.
By the way, in ie, the first time the server executes socket _ write, the return value is int (10). This is normal, and the second write operation returns int (32 ), because the php file is run in cmd, the information obtained by socket _ read is garbled (the handshake protocol is normal ), so I don't know what the information returned by the second socket _ write operation is.
Why? Obviously, the handshakes can be successful. The onopen event has been triggered. Why is there a problem when it comes to onmessage!
If the problem cannot be found based on the above information, the following is my code:
Html:
testSend《script》socket=new WebSocket("ws://localhost:1199");socket.onopen=function(){document.querySelector("#p").innerHTML="ws";}socket.onmessage=function(e){document.querySelector("#p").innerHTML=e.data;}function send(){socket.send("test");}《script》
Php:
Reference: https://segmentfault.com/q/1010000004859...