Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Support for socket.io 1.0.x #197

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

francoisTemasys
Copy link

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];

temasys support and others added 3 commits June 27, 2014 17:17
Support is only for send message/send JSON/send event without ack.
Binary are not supported.
Message are parsed more correctly (still not really full proof)
Using JsonStringify object
@bocodigital
Copy link

I'd love to get this, when do you plan to merge this in?

@scottweinert
Copy link

Agreed - this is awesome. Thank you.

@bocodigital
Copy link

sweinertjr you can just down load his fork it works great

@pkyeck
Copy link
Owner

pkyeck commented Jul 1, 2014

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 ...

@tsuncp
Copy link

tsuncp commented Jul 11, 2014

can you implement Acknowledgement function :(

@francoisTemasys
Copy link
Author

@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)

@ploddi
Copy link

ploddi commented Jul 31, 2014

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).

@Gargam
Copy link

Gargam commented Sep 3, 2014

@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
    }
});

@hongkongkiwi
Copy link
Contributor

Is this backwards compatible with Socket.IO 0.9?

@ethanmick
Copy link

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.

@Gargam
Copy link

Gargam commented Sep 13, 2014

@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.

Thanks to the suggestion of @ploddi
@francoisTemasys
Copy link
Author

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.

@bimusiek
Copy link

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.

@francoisp
Copy link

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.

hearther and others added 3 commits October 26, 2014 22:39
fix when ack number more than 1 digit
fix when ack number more than 1 digit
ack callback on with socketio 1.0
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.