I use xcode 4.6.1 cocos2d 2.x, ios sdk 6.1 , iphone 6.1 simulator.
I want to communicate from objective-c to server by node.js with socket.io.
so, I tried objective-c library called socket.io "socket.IO-objc"
https://github.com/pkyeck/socket.IO-objc
i succeeded a example "SocketTesterARC" in socket.IO-objc to communicate with server "node.js with socket.io".
SocketTesterARC :
(void) viewDidLoad {
[super viewDidLoad];
socketIO = [[SocketIO alloc] initWithDelegate:self];
[socketIO connectToHost:@"localhost" onPort:8888];
[socketIO sendEvent:@"join" withData:@"first room"];
[socketIO sendMessage:@"hihihi"];
}
so, i applied "socket.io" library to new cocos2d project. i copied from example "SocketTesterARC"'s code to new cocos2d project.
but, error and not process!
Connecting to socket with URL: http://localhost:8888/socket.io/1/?t=16807
2013-04-06 21:26:35.129 cocos2dSocketioTest[4311:c07] send()
2013-04-06 21:26:35.130 cocos2dSocketioTest[4311:c07] queue >>> 5:::{"args":["first room"],"name":"join"}
2013-04-06 21:26:35.131 cocos2dSocketioTest[4311:c07] send()
2013-04-06 21:26:35.133 cocos2dSocketioTest[4311:c07] queue >>> 3:::hihihi
2013-04-06 21:26:35.154 cocos2dSocketioTest[4311:1b03] ADDRESPONSE - ADDING TO MEMORY ONLY: http://localhost:8888/socket.io/1/?t=16807
2013-04-06 21:26:35.325 cocos2dSocketioTest[4311:c07] didReceiveResponse() 200
server error log :
info - handshake authorized brKX0Zfj9Vge80rxJfig
info - handshake authorized JsDnUP2nPXUJh83UJfih
info - handshake authorized pqoc5KS5hD2GsXcsJfii
info - handshake authorized tX3OQfsgbs-pdWFIJfij
server code :
io.sockets.on('connection', function (socket) {
console.log("connection");
//join event
socket.on('join', function(data) {
console.log('join : ' + data);
socket.join(data);
socket.set('room', data);
});
//meesage event
socket.on( 'message', function(data) {
console.log('room : ' + data );
socket.get( 'room', function(error, room) {
io.sockets['in'](room).emit('message', data);
});
});
});
plz Answer
add,successes client log :
2013-04-07 13:47:37.417 SocketTesterARC[1274:c07] Connecting to socket with URL:
http://localhost:8888/socket.io/1/?t=16807
2013-04-07 13:47:37.424 SocketTesterARC[1274:c07] send()
2013-04-07 13:47:37.424 SocketTesterARC[1274:c07] queue >>> 5:::{"args":["first room"],"name":"join"}
2013-04-07 13:47:37.425 SocketTesterARC[1274:c07] send()
2013-04-07 13:47:37.425 SocketTesterARC[1274:c07] queue >>> 3:::hihihi
2013-04-07 13:47:37.430 SocketTesterARC[1274:1b03] ADDRESPONSE - ADDING TO MEMORY ONLY: http://localhost:8888/socket.io/1/?t=16807
2013-04-07 13:47:37.436 SocketTesterARC[1274:c07] didReceiveResponse() 200
2013-04-07 13:47:37.436 SocketTesterARC[1274:c07] connectionDidFinishLoading() nTOwJjgvumKn_kNM0alf:60:60:websocket,htmlfile,xhr-polling,jsonp-polling
2013-04-07 13:47:37.436 SocketTesterARC[1274:c07] sid: nTOwJjgvumKn_kNM0alf
2013-04-07 13:47:37.448 SocketTesterARC[1274:c07] heartbeatTimeout: 67.000000
2013-04-07 13:47:37.449 SocketTesterARC[1274:c07] transports: (
websocket,
htmlfile,
"xhr-polling",
"jsonp-polling")
server log :
info - handshake authorized nTOwJjgvumKn_kNM0alf
connection
join : first room
room : hihihi
info - transport end (socket end)
i find,
cocos2d is disabled ARC therefore don't used SRWebSocket.
The way to solve ARC enable is to use.
use arc in cocos2d http://www.raywenderlich.com/23854/arc-and-cocos2d-v2-x