Default Storage
The default module for key/value storage is very simple and store the objects in-memory. So if the server dies the objects are lost. If you need reliable storage you can implement a custom storage by using Azure Storage Tables (or just a regular database of choice).
Sample
To show the storage we will just create a simple controller
using XSockets.Core.XSocket;
public class Sample : XSocketController
{
}
We do not need any methods in it since the base class has all the implementations for the storage. So now we can start the server and open up putty.
Connect and open the controller
As you can see on the image below we have connected with putty by sending in the handshake PuttyProtocol
. The server responded with a welcome message form the basic Putty protocol. Next we send in a init
(1) message to our sample controller sample|1|
. The server will respond with a open
(2) message.
We register the PersistentId
(6d3b94c4-d81f-44e8-a96d-bbd709511459) so that we can reconnect to the same context
later to see that the storage persisted our data.
Now we can store a key/value by sending controller|s1|key,value
.
Now we close the Putty client, and reconnect with the PersistentId (6d3b94c4-d81f-44e8-a96d-bbd709511459) that we got back from the first connection.
So the handshak to send in will be PuttyProtocol?PersistentId=6d3b94c4-d81f-44e8-a96d-bbd709511459
.
Now we can ask the server for the value of the key foo
, and we will get back the value bar
.