tsung icon indicating copy to clipboard operation
tsung copied to clipboard

Help: Need help how to send ping frame or respond to ping frame over websocket.

Open kishorekumark opened this issue 7 years ago • 1 comments

Hi,

My xmpp server send a ping(empty message) upon client connect over websocket, but tsung not replying back with pong. causes socket close after 60sec. Could someone help me how to enable pin-pong flow? I'm using websocket_ssl type.

Thanks, Kishore.

kishorekumark avatar Aug 20 '18 17:08 kishorekumark

I don't know is this correct or not, done following changes and Tsung starts responding for the ping. Excuse me if anything wrong, first-time I'm looking into Erlang code. I tested XMPP servers but not coded. -->ts_server_websocket_ssl.erl

{ssl, Socket, Data}->
            case websocket:decode(<<Buffer/binary, Data/binary>>) of
                more ->
                    ?DebugF("receive incomplete from server: ~p~n", [Data]),
                    loop(State#state{buffer = <<Buffer/binary, Data/binary>>});
                {?OP_PING, Payload, _} ->
                    ?DebugF("received ping from server: ~p~n", [Payload]),
                    Parent ! {gen_ts_transport, self(), Payload},
                    EncodedData = websocket:encode_pong(Payload),
                    ssl:send(Socket, EncodedData),
                    %%loop(State); 
                    loop(State#state{buffer = <<Buffer/binary, Data/binary>>});

in websocket.erl

encode_pong(Data) ->
    encode(Data, ?OP_PONG).
encode_ping(Data) ->
    encode(Data, ?OP_PING).

kishorekumark avatar Sep 14 '18 22:09 kishorekumark