0

Event not firing in following code:

    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\"     ] }");
    }    

I am using vs2012 framework 4.5 and windows application. But not able to reach the line in open and messages events. Not ure what mistake I am making, can anybody please advise?

user1254053
  • 755
  • 3
  • 19
  • 55

1 Answers1

1

First, you should setup events and after that call connect method, because it works synchronously.

private void GetWebsocketFeedMessages()
{
    string host = "wss://ws-feed.gdax.com";
    client = new WebSocket(host);
    client.OnOpen += client_OnOpen;
    client.OnMessage += client_OnMessage;
    client.Connect();
}
berserkk
  • 987
  • 6
  • 11