Comments (4)
The library itself does not contain an explicit timeout. Code 1000 (Normal Closure) is the default code, leaving me to believe that the server or the client is closing the connection directly.
Does it take 30 seconds to process one message in the large stream, or the entire stream?
Does your client code call the socket.close() method at any point?
from swiftwebsocket.
One more question.
Does your server send pings?
SwiftWebSocket sends pongs immediately following a received ping. This happens automatically in the background and is not normally something your client code needs to worry about.
If your server sends a bunch of messages and then sends a ping somewhere along the line; and your client code takes a longer time than what the server expects before receiving the pong; then it's possible that the server is closing the connection.
For example, let's say that the server sends a ping every 30 seconds with the first ping occurring immediately after the connection opens. Following the first ping, the server sends 5 large messages. The client must handle each message through event.message
in exact order prior to SwiftWebSocket responding with a pong.
But if it take more than 30 seconds to handle those 5 messages, then the server won't receive the pong prior to sending the next ping. This may cause the server to think that the client is not responding and explicitly close the connection.
If this happens to be cause of the issue, I suggest that rather than processing the message in it's entirety from inside the event.message
; just send the message into a background NSOperationQueue
(or some type of background thread) and do the processing of the message there. This will free up the websocket to return pongs and continue to run smoothly, but at the expense of having to temporary store messages in-memory.
from swiftwebsocket.
To answer the first question, it takes ~ 30 seconds to process the stream, not a single large message. Your second suggestion was one of my hunches also, so it's good to hear you second it. I'll spend some time today on this, and will close the issue if this solves it. Thanks for the insightful response!
from swiftwebsocket.
I put the messages into a background thread, and this seems to have solved the problem. Thanks -
from swiftwebsocket.
Related Issues (20)
- Substring Method Deprecated -- WebSocket.Swift
- the library is very slow
- Abnormal Closure
- How to subscribe and listen to events? HOT 1
- cannot connect with a server HOT 1
- Support Swift 4.2 on CocoaPod HOT 3
- signal SIGPIPE on device
- Swift 5.0 compile error. HOT 9
- Type 'RunLoop' has no member 'Mode' HOT 5
- Compile warning In XCode 10.2.1 with swift 5
- Take Responsibility of this project. HOT 1
- Memory Usage when sending a large message HOT 4
- WebSocketError.needMoreInput
- How do I get the HTTP response headers?
- Doesn't compile on Xcode 11.3.1 HOT 2
- 'NSObject.hashValue' is not overridable; did you mean to override 'NSObject.hash'?
- The "Autobahn Test" link doesn't work...
- Data race
- Send pongs and receive ping events. HOT 1
- Initialization of 'UnsafePointer<UInt8>' results in a dangling pointer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftwebsocket.