socket.IO-objc
socket.IO-objc copied to clipboard
Support for socket.io 1.0.x
This modification let the socket.io client connect with the 1.0.x version of socket.io and send and receive messages. Some functionalities are still missing:
- Acknowledgement
- Binary event
It has been with the following setup:
[socket sendMessage:@"Hello world"];
[socket sendMessage:@"{\"type\" : \"message sendWithout backslash\"}"];
[socket sendMessage:@"{\\\"type\\\" : \\\"message sendWith backslash\\\"}"];
[socket sendEvent:@"event" withData:@"{\"type\" : \"message sendWithout backslash\"}"];
[socket sendEvent:@"event" withData:@"{\\\"type\\\" : \\\"message sendWith backslash\\\"}"];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:@"test1" forKey:@"key1"];
[dict setObject:@"test2" forKey:@"key2"];
[socket sendJSON:dict];
[socket sendEvent:@"event" withData:dict];
I'd love to get this, when do you plan to merge this in?
Agreed - this is awesome. Thank you.
sweinertjr you can just down load his fork it works great
Thanks @francoisTemasys for this PR. I'll take a deeper look at this in the coming days.
One thing I can say right now, I won't merge this directly/completely because I don't like the v0.9/1.0 stuff. I'd rather open up a new branch which is only compatible with v1.x and drop all the old stuff - whoever is using socket.io v0.9, can use the "v0.9" branch from then on ...
can you implement Acknowledgement function :(
@pkyeck I understand your remark but here it's possible to have everything all together so why not?
@tsuncp Can you give me an server example with acknowledgement message? I'll see if I have time
(Please quote my name on the PR, I'm not checking this page every day)
PR is actually bugged.
On line 67 in SocketIOTransportWebsocket.m
:
addOnVersion = @"?EIO=2&transport=websocket&sid"
=
is missing after sid
, and server treats transport connection as new one (on server side you will get 2 connection with different sids).
@francoisTemasys Hello, thanks for your work !
For acknoledge support here a simple sample on how to do it from the server
socket.on('signin', function (nickname, callback) {
// Check if nickname is available
if (isAvailableNickname(nickname))
{
// do stuff
callback(true); // pass some data to the ack, here just a simple boolean but can be json
} else {
callback(false); // pass some data to the ack, here just a simple boolean but can be json
}
});
And from the javascript client
socket.emit('signin', 'testNickname', function (isAvailableBoolean) {
// availableBoolean is the var sent by server when using callback(var);
if (isAvailableBoolean)
{
// all good
} else {
// something went wrong
}
});
Is this backwards compatible with Socket.IO 0.9?
Hey all,
Socket 1.x support would be great, I really want to update my servers to support the new version. I understand this is a big change, so maybe I'll take a look at this PR.
I highly like @pkyeck's idea of dropping old cruft. In another year or so, having 0.9 support really won't matter.
@francoisTemasys I test your code but @ploddi is right there a missing = in your file :).
I've got the following bug using socket.io 1.1.0, not present on socket.io 1.0.6 EDIT: Not related to the version, I've got it on 1.1.0 and 1.0.6 as well.
When I try the lib with this fix I'm disconnected by the server at the first sendHeartbeat call (I think it is because the lib want to send a message to the server).
Here's my log from the app.
Found a cached session
Session opened
Connecting to socket with URL: http://localhost:3000/socket.io/1/?EIO=2&transport=polling&t=1410602002285
didReceiveResponse() 200
connectionDidFinishLoading()
VERSION 10x
Response {"sid":"ewebI7xBd6uFuDD7AAAG","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
websocket supported -> using it now
Received All information:
sid: ewebI7xBd6uFuDD7AAAG
heartbeat: 25.000000
Transport: <SocketIOTransportWebsocket: 0x7fd318793e10>
start/reset Heartbeat
Prepare to send()
send() >>> 2
didSendMessage >>> data: (null)
Prepare to send()
queue >>> 2
onDisconnect()
Disconnected Error Domain=SocketIOError Code=-4 "The operation couldn’t be completed. (SocketIOError error -4.)"
And here's the server code (really simple :p)
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
socket.on('disconnect', function () {
console.log('disconnect');
});
// socket.emit('test', { hello: 'world' });
console.log('a user connected');
console.log(socket.conn.id);
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
EDIT2:
I think I have figured out what happened, it's related to your missing =
.
When you add this missing =
the transport is succesfuly upgraded to websocket, but your heartbeat (packet @"2"
) will trigger before the "upgrade packet" (@"5"
) is sent. The server see @"2" instead of @"5" and disconnect it.
I'm looking on a simple workaround but that's not really my stuff.
Hi, Thanks for the support. As you can see I don't really have much time to put on that. But with your help I can quickly fix the issue you are reporting.
@ploddi I commited your change @Gargam It's true that the server is waiting first for the '5' message. What I don't understand is that I do the following: when the websocket gets open it launch the message '5', no matter the version (https://github.com/francoisTemasys/socket.IO-objc/blob/master/SocketIOTransportWebsocket.m#L114). The '2' is an heartbeat, one workaround would be to fix a certain delay when starting the heartbeat timer (and let the upgrade start): https://github.com/francoisTemasys/socket.IO-objc/blob/master/SocketIO.m#L465
For the acknowledgement, that's really not my priority now.
Hey guys, what needs to be done to merge this PR? I think a lot of people would really use it, even if acknowledgments are not supported.
Acks are supported in my fork of a fork, just not terribly tested.
best, F
On Oct 15, 2014, at 12:14 PM, bimusiek [email protected] wrote:
Hey guys, what needs to be done to merge this PR? I think a lot of people would really use it, even if acknowledgments are not supported.
— Reply to this email directly or view it on GitHub.