From 7e2676374cdf14c28e89d85e40f73ff0772fba6c Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 01 十一月 2019 15:49:12 +0800
Subject: [PATCH] add log

---
 server.go |   49 +++++++++++++++++++++++++------------------------
 1 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/server.go b/server.go
index d07c0f0..9576560 100644
--- a/server.go
+++ b/server.go
@@ -7,24 +7,28 @@
 	"strconv"
 	"time"
 
-	"github.com/long/test/esutil"
-	log "github.com/long/test/log"
+	"andriodServer/esutil"
+	"andriodServer/config"
+	log "andriodServer/log"
 )
 
-var addr = flag.String("addr", "0.0.0.0", "The address to listen to;")
-var Eurl = flag.String("eurl", "http://192.168.1.182:9200/", "The port to listen on; ")
-var Picurl = flag.String("picurl", "http://58.118.225.79:41242/", "picture url ")
+var addr = flag.String("addr", "0.0.0.0", "The address to listen to")
+var Eurl = flag.String("eurl", "http://192.168.1.182:9200/", "The port to listen on")
+var Picurl = flag.String("picurl", "http://58.118.225.79:41242/", "picture url")
 
-var port = flag.Int("port", 6000, "The port to listen on; ")
-var sec = flag.Int("sec", 10, "the second for query data. ")
+var port = flag.Int("port", 6000, "The port to listen on")
+var sec = flag.Int("sec", 10, "the second for query data")
 
 var Level = flag.String("level","ErrorLevel","log level")
-var ipMap map[string]net.Conn
+var IsHub = flag.String("hub", "hub", "hub is personIsHub=1")
+var Size = flag.Int("size", 100, "size default is 100")
+var env = flag.String("env", "config", "env set")
+
 func main() {
 	flag.Parse()
 
 	log.SetLogLevel(*Level)
-
+	config.Init(*env)
 	fmt.Println(*port)
 	src := *addr + ":" + strconv.Itoa(*port)
 	listener, err := net.Listen("tcp", src)
@@ -39,15 +43,9 @@
 
 	connArr:=make([]net.Conn,0)
 
-	ipMap = make(map[string]net.Conn,0)
 	for {
 		conn, err := listener.Accept()//
 
-		ipStr := conn.RemoteAddr().String()
-		if oldConn,ok := ipMap[ipStr];ok {
-			oldConn.Close()
-		}
-		ipMap[ipStr] = conn
 		connArr = append(connArr,conn)
 		if err != nil {
 			log.Log.Infoln("some connecion error: ", err)
@@ -63,13 +61,12 @@
 	ech := make(chan error)
 	go func(conn net.Conn, ech chan error) {
 		buf := make([]byte, 10)
-		for {
-			readMsg, err := conn.Read(buf)
-			log.Log.Infoln("Read completed,readMsg:",readMsg,",err:",err)
-			ech <- err
-			break
-		}
+		readMsg, err := conn.Read(buf)
+		log.Log.Infoln("Read completed,readMsg:",readMsg,",err:",err)
+		ech <- err
+
 	}(conn, ech)
+
 	tick := time.NewTicker(10 * time.Second)
 
 	for {
@@ -84,17 +81,21 @@
 			conn.Close()
 			return
 		}
-
 	}
 
 	log.Log.Infoln("Client at " + remoteAddr + " disconnected.")
 }
 
 func handleMessage(conn net.Conn, connArr []net.Conn) bool {
-	jsonstring := esutil.PostAction(*sec, *Eurl, *Picurl)
+	jsonstring := esutil.PostAction(*sec, *Eurl, *Picurl, *IsHub, *Size)
 	if jsonstring == nil {
 		log.Log.Infoln("the data is nil,remoteArr:",conn.RemoteAddr())
-		return true
+		if _, err := conn.Write([]byte("\000"));err !=nil {
+			log.Log.Infoln("conn.WriteErr:",err)
+			return false
+		} else {
+			return true
+		}
 	}
 	jsonstring = append(jsonstring, []byte("\000")...)
 	log.Log.Infoln("jsonstring len: ", len(jsonstring), "\000 data: ", len("\000"))

--
Gitblit v1.8.0