事件未在以下代码中触发:
private WebSocketSharp.WebSocket client;
private void GetWebsocketFeedMessages()
{
string host = "wss://ws-feed.gdax.com";
client = new WebSocket(host);
client.Connect();
client.OnOpen += client_OnOpen;
client.OnMessage += client_OnMessage;
}
void client_OnMessage(object sender, MessageEventArgs e)
{
string response = e.Data;
}
void client_OnOpen(object sender, EventArgs e)
{
client.Send("{ \"type\": \"subscribe\", \"product_ids\": [ \"ETH-USD\" ] }");
}
我正在使用vs2012 framework 4.5和windows应用程序。但是无法在开放和消息事件中到达该行。不知道我犯了什么错误,有人可以提出建议吗?
答案 0 :(得分:0)
首先,您应该设置事件并在调用connect
方法之后,因为它同步工作。
private void GetWebsocketFeedMessages()
{
string host = "wss://ws-feed.gdax.com";
client = new WebSocket(host);
client.OnOpen += client_OnOpen;
client.OnMessage += client_OnMessage;
client.Connect();
}