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

close, end, error never called when socket is killed (non gracefully) at the other end #119

Open
chadham opened this issue Mar 24, 2018 · 0 comments

Comments

@chadham
Copy link

chadham commented Mar 24, 2018

On Swift 4+, connecting to a web socket on an esp8266. When I restart the ESP, the socket is obviously closed, but none of the events fire in the swift code. Tried with the event methods and delegate methods....

//~~
socket = WebSocket("ws://" + IP + ":" + String(port))
        socket.delegate = self
        socket.open()
        socket.event.error = { (e) in
            print("SOCKET ERROR \(e)")
        }
        socket.event.close = { code, reason, clean in
            print("closed due to code \(code), reason \(reason), clean \(clean)")
            }
        socket.event.end = {code, reason, clean, error  in
            print("end due to code \(code), reason \(reason), clean \(clean), error \(String(describing: error))")
        }
//~~


extension WebSocketClient: WebSocketDelegate{
    func webSocketMessageText(_ text: String) {
        NotificationCenter.default.post(Notification(name: Notification.Name(rawValue:Constants.WEBSocketMessageReceived),object: self,userInfo: ["message": text]))
    }
    
    func webSocketMessageData(_ data: Data) {
        print("Websocket received data \(data)")

    }
    
    func webSocketOpen() {
        print("WEBSocket opened to \(IP):\(port)")
        connected = true
        observer.connected(client: self)
    }
    
    func webSocketClose(_ code: Int, reason: String, wasClean: Bool) {
        print("WEBSocket closed to \(IP):\(port)")
        connected = false
        observer.disconnected(client: self)
    }
    
    func webSocketError(_ error: NSError) {
        print("WEBSocket error on \(IP):\(port)")
    }
    
    func webSocketEnd(_ code: Int, reason: String, wasClean: Bool, error: NSError?) {
        print("WEBSocket closed to \(IP):\(port)")
        connected = false
        observer.disconnected(client: self)
    }
    
}
@chadham chadham changed the title close, end, error not called when socket is closed at the other end close, end, error never called when socket is killed (non gracefully) at the other end Mar 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant