socketIO problem

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)

Same problems

Still no solution for SocketIO 1.0?

Here is solution that i fixed

Edit in " SocketIO.cpp ( libNetwork ) "
in method " void SIOClientImpl::handshake() "

std::stringstream pre;
pre << "http://" << _uri << "/socket.io/1";

to

std::stringstream pre;
pre << "http://" << _uri << "/socket.io/?transport=polling&b64=0";

this is new url type of socket.io 1.xx

result :

SIOClientImpl::handshakeResponse() calledhandshake completed
response code: 200
SIOClientImpl::handshake() succeeded
SIOClientImpl::handshake() dump data: 
SIOClientImpl::openSocket() called

note: SocketIO parse still have some problems need to fix. I’ll share when its done.

thanks for your reply, but I think it’s still the same issue the author has in here : https://github.com/Automattic/socket.io/issues/1628

I don’t know if this would help or not…

http://socket.io/docs/migrating-from-0-9/#

Do you have any solution for this problem?? I have the same issue.

Hello everyone,
I’m trying to run my application with SocketIO.cpp with server node.js socket.io (vers 1.3.4 “the last one”).
I had the same problem with URL of the HttpRequest and it seems to be solved ( pre << “http://” << _uri << “/socket.io/?transport=polling&b64=0”:wink:
The next problem is that after connect immediately the client disconnect. This is the log of cocos (XCode)

[1424168964:4679] NOTICE: per-conn mem: 184 + 1594 headers + protocol rx buf
[1424168964:6258] NOTICE: libwebsocket_context_destroy
SocketIOTestLayer::onClose called

I’m working to repair this problem but I’m not sure that I finally can. If someone is working in the same topic, please suggest a new way to solve it.

Thanks in advance

:blush:谢谢楼主,解决了。