代码拉取完成,页面将自动刷新
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <wsclient/wsclient.h>
int onclose(wsclient *c) {
fprintf(stderr, "onclose called: %d\n", c->sockfd);
return 0;
}
int onerror(wsclient *c, wsclient_error *err) {
fprintf(stderr, "onerror: (%d): %s\n", err->code, err->str);
if(err->extra_code) {
errno = err->extra_code;
perror("recv");
}
return 0;
}
int onmessage(wsclient *c, wsclient_message *msg) {
fprintf(stderr, "onmessage: (%llu): %s\n", msg->payload_len, msg->payload);
return 0;
}
int onopen(wsclient *c) {
fprintf(stderr, "onopen called: %d\n", c->sockfd);
libwsclient_send(c, "Hello onopen");
return 0;
}
int main(int argc, char **argv) {
//Initialize new wsclient * using specified URI
wsclient *client = libwsclient_new("ws://echo.websocket.org");
if(!client) {
fprintf(stderr, "Unable to initialize new WS client.\n");
exit(1);
}
//set callback functions for this client
libwsclient_onopen(client, &onopen);
libwsclient_onmessage(client, &onmessage);
libwsclient_onerror(client, &onerror);
libwsclient_onclose(client, &onclose);
//bind helper UNIX socket to "test.sock"
//One can then use netcat (nc) to send data to the websocket server end on behalf of the client, like so:
// $> echo -n "some data that will be echoed by echo.websocket.org" | nc -U test.sock
libwsclient_helper_socket(client, "test.sock");
//starts run thread.
libwsclient_run(client);
//blocks until run thread for client is done.
libwsclient_finish(client);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。