How Facebook chat is working?
Asked Answered
K

2

12

How Facebook chat is working? Can anyone give me idea? I mean they are using websocket or AJAX? How they have implemented it?

Karlik answered 21/9, 2011 at 7:56 Comment(1)
Look at the facebook page using firebug; Especialy the console tab.Barbital
S
12

It's a comet (see wikipedia) model:

Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it. Comet is an umbrella term, encompassing multiple techniques for achieving this interaction. All these methods rely on features included by default in browsers, such as JavaScript, rather than on non-default plugins. The Comet approach differs from the original model of the web, in which a browser requests a complete web page at a time.

Example of comet framework is APE. It is for javascript, however comet can be written not only in javascript.

Serriform answered 21/9, 2011 at 9:59 Comment(0)
S
0

The user establishes a WebSocket connection through a process known as the WebSocket handshake. This process starts with the user sending a regular HTTP request to the server. An Upgrade header is included in this request that informs the server that the user wishes to establish a WebSocket connection. WebSocket URLs use the ws scheme. There is also wss for secure WebSocket connections which is the equivalent of HTTPS. If the server supports the WebSocket protocol, it agrees to the upgrade and communicates this through an Upgrade header in the response. Now that the handshake is complete the initial HTTP connection is replaced by a WebSocket connection that uses the same underlying TCP/IP connection. At this point either party can starting sending data.

With WebSockets you can transfer as much data as you like without incurring the overhead associated with traditional HTTP requests. Data is transferred through a WebSocket as messages, each of which consists of one or more frames containing the data you are sending (the payload). In order to ensure the message can be properly reconstructed when it reaches the client each frame is prefixed with 4-12 bytes of data about the payload. Using this frame-based messaging system helps to reduce the amount of non-payload data that is transferred, leading to significant reductions in latency.

Sentimentality answered 1/2, 2018 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.