The connection closes in about 30 seconds even though the websocket communicates every few seconds.

Asked 1 years ago, Updated 1 years ago, 135 views

I am creating a web application using websocket.
Currently, JavaScript initiates a connection with new WebSocket ("wss://{hostname}") and communicates with the server several times after onOpen is called, but even though it is not communicated, onClose always occurs in about 30 seconds and the connection is lost.
関係 I don't know if it's related, but this problem doesn't happen when I do websocket with localhost AP server in PC development environment.
If you can't even connect, or if the timeout is fast when there's no communication, I've seen a lot of solutions, but what kind of causes can you think of in my situation?
(The server uses VaporCloud with Swift, but if there is anything else besides the specific server cause, please let me know.)
Thank you for your cooperation.

javascript nginx swift4 websocket

2022-09-30 21:34

1 Answers

If it does not appear in localhost, and you connect remotely and lose connectivity in about 30 seconds each time, you will be concerned about the network configuration.

Is it possible that a load balancer or proxy is installed in the front of the AP server and the connection is cut off in 30 seconds?Or you may have similar settings on your router or terminal firewall.

If it doesn't work, I think it's because of the AP server, but there was a similar case posted on Vapor's Github.
https://github.com/vapor/vapor/issues/689#issuecomment-293737926

As a countermeasure, you can specify a timeout of more than 30 seconds.
(Regarding 2017 information)

import HTTP
HTTP.defaultServerTimeout=60*60


2022-09-30 21:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.