简体   繁体   中英

html5 websockets and long strings

I have a websocket HTML5 page that receives data from the server, but curiously the onmessage event seems to fire multiple times for long strings.

w.onmessage = function(e) {
  console.log ("\n\n message received... "+e.data);
}

If I have a string 3000 characters long, the above code will print out the first 2048 characters and then whatever is left over on the second time around.

Is there anyway for me to check for something like (pseudo-code) ( e.state == FINISHED ) or ( e.state != UPDATING ) or something so I don't execute my code until I have all of the data? Right now, the onmessage function is getting called multiple times when it receives a message and this is messing up the code.

Can you split the string in the server side? Add some thing at the end to indicate that there are more characters behind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM