IE running WebSocket problems, but Firefox is running normally.

Source: Internet
Author: User
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:


  
  
  
  test

Send《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:


  
  
  
  test

Send《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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.