2012-10-06 00:46:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <wsclient/wsclient.h>
|
|
|
|
|
2012-11-14 05:08:58 +00:00
|
|
|
int onclose(wsclient *c) {
|
|
|
|
fprintf(stderr, "Closing websocket with: %d\n", c->sockfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int onerror(wsclient *c, wsclient_error *err) {
|
|
|
|
fprintf(stderr, "Error occured (%d): %s\n", err->code, err->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
int onmessage(wsclient *c, wsclient_message *msg) {
|
2012-10-06 21:07:09 +00:00
|
|
|
fprintf(stderr, "Received (%llu): %s\n", msg->payload_len, msg->payload);
|
2012-10-06 00:46:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-06 21:07:09 +00:00
|
|
|
int onopen(wsclient *c) {
|
|
|
|
fprintf(stderr, "onopen called.\n");
|
2012-11-14 05:08:58 +00:00
|
|
|
libwsclient_send(c, "testing::testing::demo.paydensutherland.com");
|
2012-10-06 00:46:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2012-11-14 05:08:58 +00:00
|
|
|
wsclient *client = libwsclient_new("ws://ip6-localhost:8080");
|
2012-10-06 00:46:37 +00:00
|
|
|
if(!client) {
|
|
|
|
fprintf(stderr, "Unable to initialize new WS client.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-10-06 18:14:08 +00:00
|
|
|
libwsclient_onopen(client, &onopen);
|
|
|
|
libwsclient_onmessage(client, &onmessage);
|
2012-11-14 05:08:58 +00:00
|
|
|
libwsclient_onerror(client, &onerror);
|
|
|
|
libwsclient_onclose(client, &onclose);
|
2012-10-06 00:46:37 +00:00
|
|
|
libwsclient_run(client);
|
2012-10-07 22:12:44 +00:00
|
|
|
libwsclient_finish(client);
|
2012-10-06 00:46:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|