I am developing a Meteor application with two clients, one in JavaScript and the other in C. I'm actually trying to connect my C application to the server using websocket. I use the nopoll library for websocket ( http://www.aspl.es/nopoll/html/index.html ) and jansson to serialize JSON ( http://www.digip.org/jansson/ ).
I read the DDP Specification ( https://github.com/meteor/meteor/blob/devel/packages/ddp/DDP.md ) and this is a short (but good) explanation ( <a3> ).
Here is the websocket initialization code
int main(int ac, char** av)
{
noPollCtx* ctx = nopoll_ctx_new();
if (! ctx)
{
puts("Error creating nopoll context");
return EXIT_FAILURE;
}
puts("Context created");
noPollConn* conn = nopoll_conn_new(ctx, "localhost", "3000", NULL, "/websocket", NULL, NULL);
if (! nopoll_conn_is_ok(conn))
{
puts("Error creating new connection");
return EXIT_FAILURE;
}
puts("Connection created");
if (! nopoll_conn_wait_until_connection_ready(conn, 5))
{
puts("Connection timeout");
return EXIT_FAILURE;
}
puts("Connection ready");
connection_to_DDP_server(conn);
send_msg_loop(conn);
nopoll_ctx_unref(ctx);
return EXIT_SUCCESS;
}
And connection to the Meteor server
void connection_to_DDP_server(noPollConn* conn)
{
int ret = 0;
json_t* connect = json_pack("{s:s,s:s,s:[s]}",
"msg", "connect",
"version", "1",
"support", "1");
char* content = json_dumps(connect, JSON_COMPACT);
printf("DDP Connect - JSON string = %s\n", content);
ret = nopoll_conn_send_text(conn, content, strlen(content) + 1);
if (ret == -1)
{
puts("DDP Connect fail");
exit(EXIT_FAILURE);
}
printf("%i bytes written\n", ret);
}
I have this error on the server console:
I20141201-08:54:13.498(1)? Discarding message with invalid JSON
{"msg":"connect","support":["1"],"version":"1"}
, ... JSON DDP. ( , ...).