Socket.io-client-swift: ERROR SocketEngine: Engine URLSession became invalid

Created on 24 Sep 2016  ·  8Comments  ·  Source: socketio/socket.io-client-swift

I am using socket.io-client-swift 7.0.3, swift 2.2, xcode 7.3, server side socket.io 1.4.6

I am trying to connect socket server like that,
let socket = SocketIOClient(socketURL: NSURL(string: ("http://192.168.1.100:3000"))!, config: [.Log(true), .ForcePolling(true)])

and i am getting this logs;

LOG SocketIOClient: Adding handler for event: connect
LOG SocketIOClient: Adding handler for event: data
LOG SocketIOClient: Adding engine
LOG SocketEngine: Starting engine. Server: http://192.168.1.100:3000
LOG SocketEngine: Handshaking
LOG SocketEnginePolling: Doing polling request
LOG SocketIOClient: Client is being released
LOG SocketEnginePolling: Got polling response
ERROR SocketEngine: Engine URLSession became invalid
ERROR SocketEngine: Engine URLSession became invalid
LOG SocketEngine: Got message: 0{"sid":"z22pG6w4PAMqT2ISAAAI","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
LOG SocketEngine: Writing poll: has data: 0
LOG SocketEnginePolling: Sending poll: as type: 2
LOG SocketEnginePolling: Created POST string: 1:2
LOG SocketEnginePolling: POSTing
LOG SocketEngine: Engine is being released

I can connect the server from android client, but i cant connect it from ios simulator. I didn't figure out how to solve this problem.

Most helpful comment

That socket is a local variable it will be released as soon as it goes out of scope

All 8 comments

If you look at your log, you'll see that the client is being released. Which means you're not properly setting it as a property.

This my socket settings. Are there anything wrong in this code block? I just copy pasted from README.md and i only changed event name to "data" from "currentAmount".

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let socket = SocketIOClient(socketURL: NSURL(string: ("http://192.168.1.100:3000"))!, config: [.Log(true), .ForcePolling(true)])

        socket.on("connect") {data, ack in
            print("socket connected")
        }
        socket.on("data") {data, ack in
            if let status = data[0] as? String {
                print(status)
            }
        }
        socket.connect()
    }

That socket is a local variable it will be released as soon as it goes out of scope

You absolutely right about it. Now i tried and working flawlessly. Thanks for your efforts. This issue can be close now. It was my fault.

Hi @nuclearace
I got this issue:
2016-10-31 15:17:01.274 AAA[10125:3815887] LOG SocketEnginePolling: POSTing\ 2016-10-31 15:17:01.275 AAA[10125:3815887] LOG SocketEnginePolling: Doing polling request\ 2016-10-31 15:17:04.076 AAA[10125:3815233] LOG SocketEnginePolling: Got polling response\ 2016-10-31 15:17:04.077 AAA[10125:3815233] LOG SocketEnginePolling: Doing polling request\ 2016-10-31 15:17:04.080 AAA[10125:3816150] LOG SocketEngine: Got message: 0\{"sid":"PuDEqYrvZKcRiqevAjaC","upgrades":[],"pingInterval":10000,"pingTimeout":5000\}\ 2016-10-31 15:17:04.080 AAA[10125:3815233] ERROR SocketEngine: Engine URLSession became invalid\ 2016-10-31 15:17:04.080 AAA[10125:3815233] ERROR SocketEngine: Engine URLSession became invalid\ 2016-10-31 15:17:04.080 AAA[10125:3816150] LOG SocketIOClient: Starting reconnect\ 2016-10-31 15:17:04.080 AAA[10125:3815233] ERROR SocketIOClient: Engine URLSession became invalid\ 2016-10-31 15:17:04.081 AAA[10125:3815233] LOG SocketIOClient: Handling event: error with data: (\ "Engine URLSession became invalid"\ )\ 2016-10-31 15:17:04.081 AAA[10125:3816150] LOG SocketIOClient: Handling event: reconnect with data: (\ "Ping timeout"\ )\ 2016-10-31 15:17:04.082 AAA[10125:3815233] LOG SocketEngine: Engine is being closed.\ 2016-10-31 15:17:04.090 AAA[10125:3816150] LOG SocketIOClient: Trying to reconnect\ 2016-10-31 15:17:04.101 AAA[10125:3815233] LOG SocketEnginePolling: Created POST string: 1:1\ 2016-10-31 15:17:04.102 AAA[10125:3815233] LOG SocketEnginePolling: Doing polling request\ 2016-10-31 15:17:04.103 AAA[10125:3816150] LOG SocketIOClient: Handling event: reconnectAttempt with data: (\ "-1"\ )\ 2016-10-31 15:17:04.103 AAA[10125:3815233] ERROR SocketEnginePolling: The request timed out.\ 2016-10-31 15:17:04.104 AAA[10125:3815233] ERROR SocketEngine: The request timed out.\ 2016-10-31 15:17:04.104 AAA[10125:3816150] LOG SocketEngine: Starting engine. Server: http://192.688.10.15:8888\ 2016-10-31 15:17:04.105 AAA[10125:3816150] LOG SocketEngine: Handshaking\ 2016-10-31 15:17:04.105 AAA[10125:3815233] ERROR SocketIOClient: The request timed out.\ 2016-10-31 15:17:04.105 AAA[10125:3816150] LOG SocketEnginePolling: Doing polling request\ 2016-10-31 15:17:04.114 AAA[10125:3815233] LOG SocketIOClient: Handling event: error with data: (\ "The request timed out."\ )\ 2016-10-31 15:17:04.122 AAA[10125:3815233] ERROR SocketEngine: Engine URLSession became invalid\ 2016-10-31 15:17:04.122 AAA[10125:3816150] Attempted to create a task in a session that has been invalidated\ 2016-10-31 15:17:04.122 AAA[10125:3815233] ERROR SocketEngine: Engine URLSession became invalid\ 2016-10-31 15:17:04.124 AAA[10125:3815233] ERROR SocketIOClient: Engine URLSession became invalid\ 2016-10-31 15:17:04.124 AAA[10125:3815233] LOG SocketIOClient: Handling event: error with data: (\ "Engine URLSession became invalid"\ )\ 2016-10-31 15:17:04.125 AAA[10125:3816150] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Task created in a session that has been invalidated'\ *** First throw call stack:\ (0x181a96db0 0x1810fbf80 0x182083110 0x101b92458 0x101b920a0 0x101b87be8 0x101b88ce0 0x101b9e27c 0x101b9df70 0x101ba2bc4 0x101ba0404 0x101ba021c 0x101ba046c 0x101b8a540 0x101b8a21c 0x101b8b904 0x101b8bb1c 0x101b951f0 0x101b7e798 0x10247da7c 0x10247da3c 0x10248a554 0x10248172c 0x10247da3c 0x10248cc9c 0x10248c364 0x1816f9470 0x1816f9020)\ libc++abi.dylib: terminating with uncaught exception of type NSException\
It makes my app crash.
Any suggestion?

Thanks!

Emre, yardim etsene bi adamim. Bi cikaramadim. Sen simdi neyi deyistirdin? @emrekilic @emrekilic

Örnek kodları olduğu gibi viewdidload a yapıştırmaktan oluyor bu hata. socket değişkeni global tanımlanmalı. Şu şekilde;

var socket: SocketIOClient?

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
socket = SocketIOClient(socketURL: NSURL(string: (url))!, config: [.Log(true), .ForcePolling(true)])

    socket!.on("connect") {data, ack in
        print("socket connected")
    }
    socket!.on("data") {data, ack in
        if let status = data[0] as? String {
            print(status)
        }
    }
    socket!.connect()
}

Bu şekilde kullanabilirsin. Adamım?!?!?

O zaman benim karşılaştığımdan daha farklı bir hatan var demektir. Log dan anlayamadım ben hatayı. Yeni bir issue açarsan yardımcı olurlar. Kolay gelsin

Was this page helpful?
0 / 5 - 0 ratings

Related issues

janiduw picture janiduw  ·  5Comments

huangxiaolin0425 picture huangxiaolin0425  ·  6Comments

heisian picture heisian  ·  4Comments

Dohab picture Dohab  ·  4Comments

Yelles picture Yelles  ·  5Comments