O'Reilly logo

TypeScript: Modern JavaScript Development by Ivo Gabe de Wolff, Vilic Vane, Remo H. Jansen

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 the server

To add interaction to the application, we must create the server first. We will use the ws package to easily create a websocket server. On the websocket, we can send messages in both directions. These messages are objects converted to strings with JSON, just like in the previous chapters.

Connections

In the previous chapter, we wrote a connectionless server. For every request, a new connection was set up. We could store a state using a session. Such session was identified with a cookie. If you were to copy that cookie to a different computer, you would have the same session there.

Now we will write a server that uses connections. In this way, the server can easily keep track of which user is logged in and where. The server can ...

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