At work, you will encounter situations where the server wants to push data to the client. At this point, the existence of websockets comes to mind.
describe
In Java, using webSocket means that the front end uses either webSocket objects or SocketJs objects for processing. The back end establishes the corresponding webSocket path and the corresponding handler. In the selection of methods to use, here I use Spingboot+WebSocket.
problems
After the creation, there were many small episodes in the process of coordinating with the front end. First, in the stage of self-testing, the project is run locally, and the URL to be accessed uses localhost instead of IP address (domain name). At this time, there is no problem. It also maintains a long connection.
Then start thinking about the problem. The code should be fine. The maximum Http connection time in our test environment is 20 seconds. What might be wrong with the code?) and then look for the problem.
After constant testing, it was found that there was a way to test the feasibility of the environment below. That is, change the domain name of the test environment to a public Ip address + port, so that the connection can be maintained for a long time (the specific time has not been measured). However, if the domain name is used instead of Ip+ port, there will be a one-minute interruption.
Find out why
Now it is the reverse proxy problem, the Internet is all based on Nginx, Nginx solution. We won’t discuss it here. Here is the HAProxy configuration method reference. So I did a test under the test environment with the operation and maintenance brother.
Here is the configuration for a simple HAProxy
defaults
timeout tunnel 1h
timeout client-fin 30s
Copy the code
Here, my trip to the pit is also over.
Other related articles
HaProxy configuration