--- /dev/null
+/*
+ * ------------------------------------------------------------------------
+ * File Name: clock.go
+ * Author: Zhao Yanbai
+ * 2017-05-29 12:35:49 星期一 CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+package main
+
+import (
+ "io"
+ "fmt"
+ "net"
+ "log"
+ "time"
+)
+
+func main() {
+ defer fmt.Println("Clock Server Exited..")
+
+ listener, err := net.Listen("tcp", ":8000")
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ for {
+ conn, err := listener.Accept()
+ if err != nil {
+ log.Print(err)
+ continue
+ }
+
+ go handleConn(conn)
+ }
+}
+
+
+func handleConn(c net.Conn) {
+ defer c.Close()
+
+ for {
+ _, err := io.WriteString(c, time.Now().Format("2006-01-02 15:04:05\n"))
+ if err != nil {
+ return
+ }
+
+ //time.Sleep(1 * time.Second)
+ time.Sleep(100 * time.Millisecond);
+ }
+}
--- /dev/null
+/*
+ * ------------------------------------------------------------------------
+ * File Name: panic.go
+ * Author: Zhao Yanbai
+ * 2017-05-20 12:17:13 星期六 CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "runtime"
+)
+
+func main() {
+ defer fmt.Println("Program Exited...")
+ defer printStack()
+ panicFunc(3)
+}
+
+func printStack() {
+ var buf [4096]byte
+ n := runtime.Stack(buf[:], false)
+ os.Stdout.Write(buf[:n])
+}
+
+func panicFunc(n int) {
+ fmt.Printf("panicFunc(%d)\n", n+0/n)
+ defer fmt.Printf("defer panicFunc(%d)\n", n)
+ panicFunc(n - 1)
+}
--- /dev/null
+/*
+ * ------------------------------------------------------------------------
+ * File Name: select.go
+ * Author: Zhao Yanbai
+ * 2017-04-06 10:04:54 星期四 CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+package main
+import (
+ "fmt"
+ "sync"
+ "time"
+ "math/rand"
+)
+
+func main() {
+
+ data := make(chan int, 1)
+
+ var wg sync.WaitGroup
+ wg.Add(2)
+
+ go func() {
+ defer wg.Done()
+ totalSize := 0
+ for {
+ select {
+ case n := <-data:
+ fmt.Println("Received Data ", n)
+ totalSize += n
+ default:
+ fmt.Println("No Data Received")
+ }
+ fmt.Println("Received Total Size: ", totalSize)
+ time.Sleep(2*time.Second)
+ //time.Sleep(3*time.Millisecond)
+ }
+ }()
+
+
+ go func() {
+ defer wg.Done()
+ totalSend := 0
+ n := 0
+ for i :=0; i<100; i++ {
+ r := rand.Intn(100)
+ n += r
+ select {
+ case data<-n:
+ fmt.Println("Sent Data " , n)
+ totalSend += n
+ n = 0
+ default:
+ fmt.Println("No Data Sent")
+ }
+ time.Sleep(1*time.Second)
+ //time.Sleep(1*time.Millisecond)
+ }
+
+ fmt.Println("Sent Total Size: ", totalSend)
+ }()
+
+ wg.Wait()
+}
+
+