0
Cプログラム、またはChrome拡張Smart Websocketクライアントからnode.js + socket.ioに書き込まれたwebsocketサーバーに接続しようとしていますが、できません。 他のnodejsアプリケーションまたはjs + socket.ioからのみ接続できます。Cプログラムのnode.js websocketサーバーに接続
のNode.jsサーバー:
var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');
app.listen(3000);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
Cクライアント(私はgithub.com/payden/libwsclientを使用):
#include <time.h>
#include <wsclient/wsclient.h>
#include <errno.h>
int onopen(wsclient *c) {
printf("ad\n");
fprintf(stderr, "onopen called: %d\n", c->sockfd);
libwsclient_send(c, "Hello onopen");
return 0;
}
void initSocketConnection() {
//char *host = "ws://echo.websocket.org";
char *host = "ws://127.0.0.1:3000";
wsclient *client = libwsclient_new(host);
if(!client) {
fprintf(stderr, "Unable to initialize new WS client.\n");
exit(1);
}
printf("connecrionnn \n");
libwsclient_onopen(client, &onopen);
char *msg = "{\"msg\":\"STATION_READY_FOR_ACTION\", \"appKey\":\"secret-key\"}";
libwsclient_send(client, msg);
}
私が間違って何をしているのですか?
あなたはどんなエラーを取得していますか? – nilobarp
エラーはありません。なぜChrome拡張機能から接続できないのですか? Cプログラムはws://echo.websocket.orgに接続し、localhostに接続します。 – user7213585