Web Socket - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Web Socket - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript


Post Top Ad

Post Top Ad

Monday, November 26, 2018

Web Socket

Web Socket 


What Is Websocket?

The WebSocket Protocol is a widely supported open standard for developing real-time applications. Previous methods for simulating full-duplex connections were based on polling, a synchronous method wherein the client makes a request to the server to see if there is any information available. The client receives a response from the server even if there is no information available.
websocket server

WebSocket is a communications protocol for a persistent, bi-directional, full duplex TCPconnection from a user’s web browser to a server.
A WebSocket connection is initiated by sending a WebSocket handshake request from a browser’s HTTP connection to a server to upgrade the connection. Along with the upgrade request header, the handshake request includes a 64-bit Sec-WebSocket-Key header. The server responds with a hash of the key in a Sec-Websocket-Auth header. This header exchange prevents a caching proxy from resending previous WebSocket exchanges.
WebSockets: how it works and 
how to use it

websocket work

WebSocket is an advanced technology that allows you to start bi-directional cummunication session between the browser and the server. Thanks to this protocol it is possibility to send request to the server and receive an answer as events, what means that you don't have to re-send the request to the server. WebSockets bring many benefits and it can be used in a various projects. Learn why you should and how to use this technology.

How it works?

websocket works

Websockets is a web technology, which allows bi-directional, real-time communications between web client and a server. As  part of the HTML5 specification it works with the newest web browsers (including Internet Explorer 10 and its latest versions).
Every connection begins as HTTP to provide full support for legacy solutions. Web client sends a request to the server and, if the server supports the WebSockets protocol, it sends a response, in which it overwrites the connection header. Since this moment a WebSockets-based connection is made.

Create a WebSocket Connection

To connect to a remote host, create a new WebSocket object instance and provide the new object with the URL of the target endpoint.
A WebSocket connection is established by upgrading from the HTTP protocol to the WebSocket Protocol during the initial handshake between the client and the server, over the same underlying TCP connection. An Upgrade header is included in this request that informs the server that the client wishes to establish a WebSocket connection. Once established, WebSocket messages can be sent back and forth using the methods defined by the WebSocket interface.

websocket connection in java

To create a connection, call Javascript’s WebSocket constructor, which returns the connection instance object. You can then listen for events on that object. These events are triggered when the connection opens or closes, messages arrive, or errors occur. You can interact with the WebSocket instance to send messages or close the connection.
The WebSocket constructor takes one required argument: the URL to which we want to connect. There is one optional argument that specifies a protocol.

WebSockets fast as lightning

According to some studies WebSockets protocol is three times faster than HTTP, what means the improvement of the speed of data exchange between applications. One of the biggest advantages of using WebSockets is that it doesn't interfere with firewalls and proxy servers, which was the bane of the most solutions.
The most common examples of the WebSockets protocol usage are real-time applications such as IM, collecting and analysing data, ducuments cooperation or browser games.
WebSocket for Developers and Architects
websocket server architecture
 Web Socket is an independent TCP-based protocol, but it is designed to support any other protocol that would traditionally run only on top of a pure TCP connection.
  Web Socket is a transport layer on top of which any other protocol can run. The Web Socket API supports the ability to define sub-protocols: protocol libraries that can interpret specific protocols.
  Examples of such protocols include XMPP, STOMP, and AMQP. The developers no longer have to think in terms of the HTTP request-response paradigm.
  The only requirement on the browser-side is to run a JavaScript library that can interpret the Web Socket handshake, establish and maintain a Web Socket connection.
  On the server side, the industry standard is to use existing protocol libraries that run on top of TCP and leverage a Web Socket Gateway.

What are the benefits of WebSockets?

benefits of websocket

WebSockets, part of the HTML5 specification, enables two-way communication between web pages and a remote host. The protocol is designed to achieve the following benefits:
  • Reduce unnecessary network traffic and latency using full-duplex through a single connection (instead of two).
  • Streaming through proxies and firewalls, supporting simultaneously upstream and downstream communication.
  • Backward compatible with the pre-WebSocket world by switching from an HTTP connection to WebSockets.

No comments:

Post a Comment

Post Top Ad