I’m testing server with node.js
and socket.io package version is lastest… -> 1.0.4
My server code is like below very simple
// server
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(9000);
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.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
and client is cocos2dx test project
// client
'Extensions - SocketIOTest' of cocos2d-x lastest version 3.1.0
Cpp Tests
and modified this line for connect to my node.js server
void SocketIOTestLayer::onMenuSIOClientClicked(cocos2d::Ref *sender)
{
//create a client by using this static method, url does not need to contain the protocol
// this line
_sioClient = SocketIO::connect("http://127.0.0.1:9000", *this);
//you may set a tag for the client for reference in callbacks
_sioClient->setTag("Test Client");
//register event callbacks using the CC_CALLBACK_2() macro and passing the instance of the target class
_sioClient->on("testevent", CC_CALLBACK_2(SocketIOTestLayer::testevent, this));
_sioClient->on("echotest", CC_CALLBACK_2(SocketIOTestLayer::echotest, this));
}
and push ‘Open SocketIO Client’ menu item
error like below
SIOClientImpl::init() successful
SIOClientImpl::handshake() called
SIOClientImpl::handshake() waiting
Curl curl_easy_getinfo failed: No error
SIOClientImpl::handshakeResponse() called
handshake completed
response code: 400
SIOClientImpl::handshake() failed
error buffer:
SocketIOTestLayer::onError received:
it looks like handshaking error…
in socket.io version 0.9 it works.
but new version of socket.io doesn’t
any solutions?
Screenshot_2.png (120.3 KB)