我正在使用 XSockets 3.x(最新)。
我已经设置了一个控制器:
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"));
}
}
可以看出,它只是一个基本的控制器,监听连接并在建立新连接后通知每个人,但是,它不起作用 - 没有收到消息。Chrome 的开发工具也没有显示任何框架。
我的网络客户端:
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);
});
我在控制台中看到以下输出:
这在Network选项卡 -> Frames中:
SendToAll
我可以通过将调用推迟到 a 来解决这个问题System.Threading.Timer
。我的调试显示,50ms 不一致,所以我将它设置为 300ms,它似乎工作正常,但计时器感觉非常糟糕。
我该如何解决这个问题?
当 XSockets 真的为客户端准备好时,是否有我可以监听的事件?