BTCTrader / broker-api-docs

The documentation for BTCTrader's white label exchange platform API. Use this documentation to access the APIs of BTCTurk other BTCTrader partners.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C# websocket ping

zerefsong opened this issue · comments

I use C #'s websocket library, the server always disconnects after connecting for more than a minute, I will send "ping" to the server every 30 seconds. keepAlive is also set to 30 seconds, but it has no effect.

hi,

you won't send ping, you should send pong instead.

javascript code example

    conn.on('ping', (payload) => {
      conn.pong(payload)
    })

Hi,
C# WebSocket library should handle this automatically. There may be an error in your code. As the connection state is open, you should expect the message.

The sample code should be as follows. If you edit the code this way, I expect you will not get an error.

            using (var socket = new ClientWebSocket())
            {
                await socket.ConnectAsync(new Uri("wss://ws-feed-pro.btcturk.com"), cancellationToken);

                //send subscription request
                
                while (_clientWebSocket.State == WebSocketState.Open)
                {
                    var resultMessage = await ReceiveMessageAsync(socket, cancellationToken);    
                }

            }