]> Zhao Yanbai Git Server - acecode.git/commitdiff
...
authorAceVest <zhaoyanbai@126.com>
Tue, 16 May 2017 15:24:18 +0000 (23:24 +0800)
committerAceVest <zhaoyanbai@126.com>
Tue, 16 May 2017 15:24:18 +0000 (23:24 +0800)
learn/go/SimpleSvr.go [new file with mode: 0644]

diff --git a/learn/go/SimpleSvr.go b/learn/go/SimpleSvr.go
new file mode 100644 (file)
index 0000000..6512f41
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: SimpleSvr.go
+ *      Author: Zhao Yanbai
+ *              2017-05-15 23:23:38 Monday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+package main
+
+import (
+       // "bufio"
+       // "fmt"
+       "log"
+       "net"
+)
+
+func handleConn(conn net.Conn) {
+       who := conn.RemoteAddr().String()
+       /*
+               input := bufio.NewScanner(conn)
+               for input.Scan() {
+
+               }
+       */
+       //fmt.Println(who)
+       log.Print(who + " connected to the server")
+
+       conn.Close()
+}
+
+func main() {
+       defer log.Print("Program Exited...")
+       log.Print("Program Started...")
+
+       //listener, err := net.Listen("tcp", "localhost:6666")
+       listener, err := net.Listen("tcp", "10.135.190.233:6666")
+       if err != nil {
+               log.Fatal(err)
+       }
+
+       for {
+               conn, err := listener.Accept()
+               if err != nil {
+                       log.Print(err)
+                       continue
+               }
+
+               go handleConn(conn)
+       }
+}