This is a created article in which the information may have evolved or changed.
When we use TCP IP communication, we need to use the heartbeat mechanism to determine the connection state between the server and the client, if the server's heartbeat timeout, and so on, will make a reconnection mechanism,
Based on this problem, I recommend to you today a Go language based heartbeat response mechanism, not much nonsense to say directly on code:
The source is here.
# Heartbeat The heartbeat timer
Heartbeat Introduction
Heartbeat is a go-based multi-task timed response callback
# # Install Go get-u github.com/noaway/heartbeat
Simple use of heartbeat
Create a task
Name, Spec: = "12138", 5HT, err: = Heartbeat. Newtast (name, spec) If err! = Nil {fmt. PRINTLN (Err)}//Run a new missionht. Start (func () error {//call The callback every 5 secondsfmt. PRINTLN (name) return nil})
The use of the method is very simple, as long as the description of the way to start the document can be, in the future development of the process will be added some automated features.
The source is here.