shuoli84 / SocketIOCocoa

The socket 1.0 client in Swift
175 stars 11 forks source link

EXC_BREAKPOINT #20

Open naartjie opened 9 years ago

naartjie commented 9 years ago

I am getting an EXC_BREAKPOINT on this line

screen shot 2015-02-19 at 16 28 59

I am using socket.io v1.3.4, and engine.io v1.5.1, and SocketIOCocoa from master. On the server my code looks like this:

var socketio = require('socket.io'),
  io = socketio(server);

io.of('/brand/root').on('connection', function(socket) {

    var interval = setInterval(function() {
        console.log('sending foo');
        socket.emit('foo', {bar: 'baz'});
    }, 40*1000);

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

    socket.on('test', function(data, fn) {
        console.log('server got test event', data);
        fn('ack from server');
    });

    socket.emit('test', {server: 'from on.connection'}, function(data) {
        console.log('got ack from client', data);
    });
});

And on the client:

import Foundation

@objc class Sockets : NSObject, SocketIOSocketDelegate {

    func start() {
        var client = SocketIOClient(uri: "http://localhost:3000/socket.io/", reconnect: true, timeout: 30, transports: ["websocket"])
        client.open()
        var socket = client.socket("/brand/root")
        socket.delegate = self
    }

    func socketOnEvent(socket: SocketIOSocket, event: String, data: AnyObject?){
        println("got event \(event) \(data)")
    }

    func socketOnPacket(socket: SocketIOSocket, packet: SocketIOPacket) {
        println("socket packet \(packet.data))")
    }

    func socketOnOpen(socket: SocketIOSocket) {
        println("socket open")
        socket.event("test", data: [1, 2, 3]) { (packet) -> Void in
            println("got ack from server \(packet.data)")
        }
    }

    func socketOnError(socket: SocketIOSocket, error: String, description: String?) {
        println("socket error \(error)")
    }
}
naartjie commented 9 years ago

screen shot 2015-02-19 at 16 51 00

The first screenshot is one stack level lower.

naartjie commented 9 years ago

Hmm, when I change the connection line to use the defaults:

var client = SocketIOClient(uri: "http://localhost:3000/socket.io/")

It doesn't happen anymore.

But after a while the client gets disconnected on the server side: screen shot 2015-02-19 at 17 35 34

While the client side doesn't seem to know anything about it. Well, there are no pings going backwards and forwards, but when I kill the server, Xcode console shows this: screen shot 2015-02-19 at 17 40 21

I should have probably mentioned before, I am running this on the iOS Simulator (both client and server running on the same machine), do I need to tweak anything, or should it work out the box?

naartjie commented 9 years ago

@shuoli84 I realise now that this is probably 2 separate issues. Unless it's something obvious I am doing wrong, I can move the second one into new issue.

shuoli84 commented 9 years ago

from the code:

var client = SocketIOClient(uri: "http://localhost:3000/socket.io/", reconnect: true, timeout: 30, transports: ["websocket"])
        client.open()
        var socket = client.socket("/brand/root")
        socket.delegate = self

Seems you not retain any reference on client. Anyway, the lib should not crash. I'll fix it.