Using STATE
State is one of the most important things in real-time communication. State is what will make your life as a developer much easier when it comes to developing real-time systems.
Why do we say that?
- We have a full-duplex (open) connection, so use STATE!
- STATE will reduce development time
- STATE will decrease the size of your messages
- STATE will reduce complexity of your application
- STATE will be persisted and re-populated when you reconnect
The only drawback with STATE is that it will become a challenge when you ScaleOut.
Not convinced?
You may not be convinced after the 5 statements above, so let's take a closer look at each statement.
We have a full-duplex (open) connection, so use STATE!
Since XSockets always offer a full-duplex connection it makes sense to use STATE
. That way the server will know the details (you want to share) about each client and that way the server can also target clients individually.
STATE will reduce development time
Handling STATE
in half-duplex environments is a complex task, but when you have a full-duplex environment it is extremely easy to use a programming model with STATE
. This fact will reduce the efforts needed to create complex systems/applications.
STATE will decrease the size of your messages
When we use STATE
the server will know about the details we want to share from each client. So, there is no need to send information already known by the server. A simple example of this is if you have a chat and log-on with a user name. You only need to tell the server about the name once, and just send the message in the chat. So the payload sent will be reduced thanks to STATE
.
STATE will reduce complexity of your application
If you do not have STATE
you do not know details about the clients connected. If you do not know details you cant target a subset of the connected clients. If you can target a subset of clients you have a poor and chatty system/application. You will also have security issues in some cases.
On the other hand, if you have STATE
you can easily target clients based on the details. A very crucial part of real-time communication.
Yet another advantage whit STATE
is that you can combine the details in an easy way to target clients in a way that basic Pub/Sub cant do.
See the section about Communication Patterns
STATE will be persisted and re-populated when you reconnect
Since XSockets offer you to have PersistentProperties
you actually only have to send information once if you have STATE. When/If a connection is broken the server will remember the STATE and re-populate that information when the connection is re-established.