建立Meteor Server和C app之间的DDP连接

我正在开发一个带有两个客户端的Meteor应用程序,一个是JavaScript,另一个是C.我实际上是尝试使用websocket将我的C应用程序连接到服务器。 我正在使用库nopoll作为websocket( http://www.aspl.es/nopoll/html/index.html )和jansson作为JSON序列化( http://www.digip.org/jansson/ )。

我阅读了DDP规范( https://github.com/meteor/meteor/blob/devel/packages/ddp/DDP.md )和这个简短(但很好)的解释( https://meteorhacks.com/introduction-to -ddp.html )。

这里的代码是websocket初始化

int main(int ac, char** av) { // Create noPoll context noPollCtx* ctx = nopoll_ctx_new(); if (! ctx) { puts("Error creating nopoll context"); return EXIT_FAILURE; } puts("Context created"); // Create connection 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"); // Wait until connection is ready 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; } 

和Meteor服务器的连接

 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); } 

我在服务器控制台上有这个错误:

 I20141201-08:54:13.498(1)? Discarding message with invalid JSON {"msg":"connect","support":["1"],"version":"1"} 

我不明白为什么……我发送有效的JSON并参考DDP文档,我做得很好(至少我认为是这样……)。

问题是我发送的1个字符比通常预期的要多。 现在,我得到一个:

 {"msg":"connected","session":"HupHMhcFK4avy4vwg"} 

告诉我,我已经联系了。

我发送’\ 0’并且JSON解析器无法识别它。