O'Reilly logo

Dart Essentials by Martin Sikora

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing a chat app with the WebSockets server

WebSockets is a protocol for bidirectional communication between a web browser and a server. The fact that a server can actively send you messages is the most important thing and is probably the only reason why you might want to use WebSockets in the future. There used to be some fallbacks for browsers that don't support WebSockets, such as long pooling, but we're not going to use any of them and assume that our browsers are up to date with proper WebSockets support.

Our chat WebSockets server spawns an HTTP server that listens to WebSockets headers and implements a handshake between the two endpoints to switch to the WebSockets protocol (the so-called upgrade request).

Later, we'll log all chat messages ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required