package main
import (
- // "bufio"
- // "fmt"
+ "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")
+ input := bufio.NewScanner(conn)
+ for input.Scan() {
+ fmt.Println(input.Text())
+ }
+
+ fmt.Println(who)
+
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")
+ log.Print(net.LookupHost("www.qq.com"))
+ return
+ listener, err := net.Listen("tcp", "localhost:6666")
+ //listener, err := net.Listen("tcp", "10.135.190.233:6666")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Version B: Value of items: %v (Invalid Method) \n", items)
}
+
+ var m1 map[string]int // 此时m1==nil
+ m1 = make(map[string]int) // 如果不为m1分配空间
+ m1["test"] = 1 // 那么这一句会panic
+
+ var m2 = make(map[string]int)
+ m2["test"] = 2
+
+ m3 := make(map[string]int)
+ m3["test"] = 3
}
--- /dev/null
+/*
+ * ------------------------------------------------------------------------
+ * File Name: reflect.go
+ * Author: Zhao Yanbai
+ * 2017-05-31 21:24:09 Wednesday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+package main
+import (
+ "fmt"
+ "reflect"
+)
+
+func main() {
+ defer fmt.Println("Program Exited...")
+
+ var a float32 = 6.18
+ v := reflect.ValueOf(a) // Copy
+
+ fmt.Printf("Type %s Value %v Value %f Value %s\n", reflect.TypeOf(a), v, v, v.String()) // reflect.ValueOf(a), reflect.ValueOf(a).String())
+
+ fmt.Println("Value: ", v)
+ fmt.Println("Type: ", v.Type())
+ fmt.Println("Value Kind: ", v.Kind())
+ fmt.Println("Value: ", v.Float())
+ fmt.Println("Interface: ", v.Interface())
+
+ b := v.Interface().(float32)
+ fmt.Println(b)
+
+
+ // v.SetFloat(3.14) // panic: reflect: reflect.Value.SetFloat using unaddressable value
+
+ fmt.Println("Settability of v:", v.CanSet())
+
+
+ p := reflect.ValueOf(&a)
+ fmt.Println("Type of p:", p.Type())
+ fmt.Println("Settability of p:", p.CanSet())
+ fmt.Println("The Element Of p:", p.Elem())
+ fmt.Println("Settability of p.Elem:", p.Elem().CanSet())
+ p.Elem().SetFloat(3.14)
+ fmt.Println("p.Elem.Interface:", p.Elem().Interface())
+ fmt.Println("p.Elem:", p.Elem())
+ fmt.Println("a:", a)
+}