From: AceVest Date: Tue, 16 May 2017 15:24:18 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=66f2959f79b53ba7aec89f5ea9e92ecfe59a0150;p=acecode.git ... --- diff --git a/learn/go/SimpleSvr.go b/learn/go/SimpleSvr.go new file mode 100644 index 0000000..6512f41 --- /dev/null +++ b/learn/go/SimpleSvr.go @@ -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) + } +}