Giter VIP home page Giter VIP logo

Comments (4)

tidwall avatar tidwall commented on July 23, 2024

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.

tidwall avatar tidwall commented on July 23, 2024

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.

siegesmund avatar siegesmund commented on July 23, 2024

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.

siegesmund avatar siegesmund commented on July 23, 2024

I put the messages into a background thread, and this seems to have solved the problem. Thanks -

from swiftwebsocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.