|
|
|
@ -1,15 +1,22 @@
|
|
|
|
|
#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) {
|
|
|
|
@ -19,12 +26,13 @@ int onmessage(wsclient *c, wsclient_message *msg) {
|
|
|
|
|
|
|
|
|
|
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/");
|
|
|
|
|
wsclient *client = libwsclient_new("ws://localhost:8080");
|
|
|
|
|
if(!client) {
|
|
|
|
|
fprintf(stderr, "Unable to initialize new WS client.\n");
|
|
|
|
|
exit(1);
|
|
|
|
|