forked from jettyu/C1000kPracticeGuide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
48 lines (38 loc) · 747 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"net"
"time"
)
var array []byte = make([]byte, 500)
func checkError(err error, info string) (res bool) {
if err != nil {
fmt.Println(info + " " + err.Error())
return false
}
return true
}
func Handler(conn net.Conn) {
// fmt.Println("connection is connected from ...", conn.RemoteAddr().String())
for {
_, err := conn.Write(array)
if err != nil {
return
}
time.Sleep(10 * time.Second)
}
}
func main() {
for i := 0; i < 500; i += 1 {
array[i] = 'a'
}
service := ":8888"
tcpAddr, _ := net.ResolveTCPAddr("tcp4", service)
l, _ := net.ListenTCP("tcp", tcpAddr)
for {
// fmt.Println("Listening ...")
conn, _ := l.Accept()
//fmt.Println("Accepting ...")
go Handler(conn)
}
}