1

We are using WebSocket & super socket for real-time notification in our project. In between the connections are broken due to which in browser the notifications are not received

The possible solution we got is of using PING/PONG. But, could not find any implementation for it. It would really great if any expert for this can help us out with the solution.

finn
  • 31
  • 3

1 Answers1

0

In SuperSocket.net, you could define a WebSocketPackage object, there is a OpCode enum property, use OpCode.Ping or OpCode.Pong to send package.

//this enum is define in SuperSocket.WebSocket
namespace SuperSocket.WebSocket
{
    public enum OpCode : sbyte
    {
        Handshake = -1,
        Continuation = 0,
        Text = 1,
        Binary = 2,
        Close = 8,
        Ping = 9,
        Pong = 10
    }
}
public async Task WSMessageHandlerAsync(WebSocketSession session, WebSocketPackage message){
    if (message.OpCode != OpCode.Ping){
        var pong = new WebSocketPackage(){
            FIN = true,
            OpCode = OpCode.Pong
        };
        //you could save the session and send ping or pong any time.
        await session.SendAsync(pong);
    }
}
Peter-Yu
  • 191
  • 7