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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access