Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

ความแตกต่างระหว่าง MessageChannel และ WebSockets ใน HTML5

Web Sockets เป็นเทคโนโลยี bidirectional communication รุ่นใหม่สำหรับเว็บแอป ทำงานผ่าน single socket และ expose ผ่าน JavaScript interface ใน HTML5 compliant browsers เมื่อได้ Web Socket connection กับเว็บเซิร์ฟเวอร์ สามารถส่งข้อมูลจาก browser ไป server ด้วย send() และรับข้อมูลจาก server ผ่าน onmessage event handler

Two-way communication ระหว่าง browsing contexts เรียกว่า channel messaging มีประโยชน์สำหรับ communication ข้าม multiple origins

ขณะสร้าง messageChannel จะสร้าง two ports ภายในสำหรับส่งข้อมูลและ forward ไปยัง browsing context อื่น