ricardopereira / SocketIO-Kit

Socket.io iOS and OSX Client compatible with v1.0 and later
https://ricardopereira.github.io/SocketIO-Kit
MIT License
139 stars 12 forks source link

Disconnection #13

Closed chasseurmic closed 9 years ago

chasseurmic commented 9 years ago

I am trying out the library and cannot understand why I get unexpected disconnections from the client that I cannot debug. The server (socket.io 1.3.5) gives me a disconnection warning, but on my iOS device the on(.Disconnected)() function never gets called. Any idea if this is an issue? The disconnection happens after a short time (some 20/30 sec) of inactivity on the socket.

ricardopereira commented 9 years ago

The disconnection happens after a short time (some 20/30 sec) of inactivity on the socket.

I will make some tests. Can you create a small example of the server?

chasseurmic commented 9 years ago

This is the server side (index.js) with express and socket.io as dependencies. It's very basic:

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

var devices = [];

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
});

io.on('connection', function(socket){
  console.log('a user connected');

  socket.on('disconnect', function(){
    console.log('user disconnected');
  });

});

http.listen(3000, function(){
  console.log('listening on *:3000');
});
ricardopereira commented 9 years ago

Thank you.

I'm suspicious that is a problem with the WebSocket heartbeat.

chasseurmic commented 9 years ago

Hope it helps! Thanks.

ricardopereira commented 9 years ago

Possible solution with #7

ricardopereira commented 9 years ago

I replaced the WebSocket implementation. It was something that I wanted to do and I hope that it fixes this problem.

If your are using CocoaPods, please do pod update and test it again. Thanks.

chasseurmic commented 9 years ago

Seems to work right now. Good job! +1

ricardopereira commented 9 years ago

Awesome!

I added a new event: TransportError.

Example:

on(.TransportError) {
    switch $0 {
    case .Failure(let error):
        println("WebSocket error: \(error)")
    default:
        break
    }
}