Closed zivelli closed 9 years ago
If you see an open event, then you should see a close event once the underlying tcp connection has been terminated by the server. Either the server hasn't completely closed the socket, or you've encountered a bug.
Is this problem happening for you with the echo example in the README file?
Also, there's an end
event that is guaranteed to fire regardless of connection state.
There is also an error
event that could provide some insight in what's happening.
Does the end
and/or error
events happen to fire?
With the included echo example I can get the following results with tests
Which means I can perform any checks or reconnects as websocket thinks TCP is still open.
Thanks. This is good information. I'll look into asap.
On a side note, I recommend moving the 2.0 version when you get the chance. It's actively supported and has some tremendous enhancements compared to 1.2.
I also added the end event to the echo test example. I can verify that it fires when the func is first called but if I shut down the server I don't get an error, close or end trigger.
To test the server I used a TestChat app demoing SocketIO. If I shut down the server a Connection Closed event was fired.
Yeah that sounds like a bug of some sort. Did you test with the Javascript SocketIO client?
OK I'll look into the 2.0 version, does this mean a move to Xcode 7 & OSX 10.11? I running a few project in Xcode 6.4 and things are stable
No I used this as a client test https://github.com/TeehanLax/SwiftSocketIODemo
Yeah, the 2.0 version does require Xcode 7. :(
OK, I must be doing something wrong. I've got Xcode 7 and I'm running the Echo Test. I can't get a close server or disconnected message to fire if I quit the server.
The close message is only fired if the server is not running, when I first run the echo test.
Maybe I'm misunderstanding the sequence of triggered events. Will the 'close event' only fire after I init WebSocket
var ws = WebSocket("ws://localhost:90993")
Will it not fire like event.message?
SwiftWebSocket events work just like the JS WebSocket version, with the addition of the end convenience event.
error: Fires when an error is encountered. open: Fires only when a valid websocket connection is made with the server. message: Fires messages close: Fires only when a valid websocket connection is made, and the server sends a close message or when the tcp connection terminates. end: Fires when the WebSocket object is no longer in use. This will always fire once and will always be the last event to fire.
At a minimum you should see an open event or an error event describing the reason for the failure. You will also see the end event. You will only see the open and close event if a valid connection was made to the server.
var ws = WebSocket("ws://localhost:90993")
Will attempt to open a connection with the server. If successful the event.message will handle the server messages.
The event.close will fire when the server sends a close message or the TCP terminates.
I'm looking into the problem right now. I'll keep you posted.
I just pushed an update to master. This should address the problem that you are seeing. Let me know if it does. This is for the 2.0 version.
I can verify that the close event is firing when I drop the connection.
Thanks so much!
No problem. And thanks for your help too.
I am using the 1.2 branch and everything seems to work well except I do not receive an event when there is a server disconnection
websocket.event.close = { (code, reason, clean) in println("web server socket close") }
event.message, event.open are working.