Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not handle pingpong to keep alive. #13

Open
PixMod opened this issue Jul 11, 2019 · 1 comment
Open

Not handle pingpong to keep alive. #13

PixMod opened this issue Jul 11, 2019 · 1 comment

Comments

@PixMod
Copy link

PixMod commented Jul 11, 2019

Ref websocket rfc

5.5.2. Ping

The Ping frame contains an opcode of 0x9.

A Ping frame MAY include "Application data".

Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in
response, unless it already received a Close frame. It SHOULD
respond with Pong frame as soon as is practical. Pong frames are
discussed in Section 5.5.3.

An endpoint MAY send a Ping frame any time after the connection is
established and before the connection is closed.

NOTE: A Ping frame may serve either as a keepalive or as a means to
verify that the remote endpoint is still responsive.

5.5.3. Pong

The Pong frame contains an opcode of 0xA.

Section 5.5.2 details requirements that apply to both Ping and Pong
frames.

A Pong frame sent in response to a Ping frame must have identical
"Application data" as found in the message body of the Ping frame
being replied to.

If an endpoint receives a Ping frame and has not yet sent Pong
frame(s) in response to previous Ping frame(s), the endpoint MAY
elect to send a Pong frame for only the most recently processed Ping
frame.

@savethebeesandseeds
Copy link

This solution work for me:
Small changes where needed:


on the header file wsclient.h search for line:


int libwsclient_send(wsclient *client, char *strdata);


change it to:


int libwsclient_send(wsclient *client, char *strdata, int opcode);


make sure also to update the file wsclient.c:


int libwsclient_send(wsclient *client, char *strdata, int opcode);


Last change is intended to allow parsing the opcode in the libwsclient_send method.
Next:


on the file wsclient.c
inside the function libwsclient_send()
search for the line:


finNopcode = 0x81; //FIN and text opcode.


change it to:


if(opcode==-1){
finNopcode = 0x81; //FIN and text opcode.
} else {
finNopcode = opcode;
}

make sure on every usage to the function libwsclient_send(.., ..., -1) to parse a -1 value in the last argument.


except for when dealing with control frames


on payden's library, control frame are deal on the file wsclient.c with in the function:


void libwsclient_handle_control_frame(wsclient *c, wsclient_frame *ctl_frame)


search for it, and note the swtich case


option codes (opcode) are the key here:
0x8 marks the end of the websocket conexion.
0x9 is ping
0xA is pong


libwsclient is a client interface, so most likely only the 0x9 is needed, and to it one must respond with a 0xA.


easy enough, inside the function void libwsclient_handle_control_frame()
add a case 0x9:


case 0x9:
int n = libwsclient_send(c, ctl_frame->rawdata, 0xA);
if(n=0x00) {
err = libwsclient_new_error(WS_HANDLE_CTL_FRAME_SEND_ERR);
err->extra_code = n;
c->onerror(c, err);
free(err);
err = NULL;
}
break;

no further changes are required


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants