I am using XSockets 3.x (latest).
I have set up a controller:
public class NotificationsController : XSocketController
{
public NotificationsController()
{
// Bind an event for once the connection has been opened.
this.OnOpen += OnConnectionOpened;
// Bind an event for once the connection has been closed.
this.OnClose += OnConnectionClosed;
}
void OnConnectionOpened(object sender, XSockets.Core.Common.Socket.Event.Arguments.OnClientConnectArgs e)
{
// Notify everyone of the new client.
this.SendToAll(new TextArgs("New client. Called right from OnConnectionOpened.", "notify"));
}
}
As can be seen, it's just a basic controller, listening for connections and informing everyone once a new connection is made, though, it doesn't work - the message is not recieved. Chrome's dev-tools show no Frame either.
My web-client:
var xs = new XSockets.WebSocket("ws://" + window.location.hostname + ":1338/notifications");
xs.onopen = function(e)
{
console.log("Connected", e);
};
xs.on('notify', function(data)
{
console.log(data);
});
I am presented with the following output in console:
And this in the Network tab -> Frames:
I can fix the issue by deferring the SendToAll
call to a System.Threading.Timer
with some timeout. My debugging showed, that 50ms is not consistent, so I have set it up to 300ms and it seems to be working okay, but the timer feels very hacky.
How do I fix the problem?
Is there, maybe, an event I can listen to, when XSockets really is ready for the client?