| | |
| | | |
| | | }(conn, ech) |
| | | |
| | | tick := time.NewTicker(10 * time.Second) |
| | | |
| | | tick := time.NewTicker(3 * time.Second) |
| | | lastTime := time.Now() |
| | | for { |
| | | select { |
| | | case <-tick.C: |
| | | if !handleMessage(conn, connArr){ |
| | | curTime := time.Now() |
| | | if !handleMessage(conn, connArr, lastTime, curTime){ |
| | | conn.Close() |
| | | return |
| | | } |
| | | lastTime = curTime |
| | | case err := <-ech: |
| | | log.Log.Infoln(err, "remoteAddr ", remoteAddr, " close") |
| | | conn.Close() |
| | |
| | | log.Log.Infoln("Client at " + remoteAddr + " disconnected.") |
| | | } |
| | | |
| | | func handleMessage(conn net.Conn, connArr []net.Conn) bool { |
| | | jsonstring := esutil.PostAction(*sec, *Eurl, *Picurl, *IsHub, *Size) |
| | | func handleMessage(conn net.Conn, connArr []net.Conn,lastT time.Time, curTime time.Time) bool { |
| | | jsonstring := esutil.PostAction(*sec, *Eurl, *Picurl, *IsHub, *Size, lastT, curTime) |
| | | if jsonstring == nil { |
| | | log.Log.Infoln("the data is nil,remoteArr:",conn.RemoteAddr()) |
| | | if _, err := conn.Write([]byte("\000"));err !=nil { |