~rbn/neinp

ref: b441da6dea2e963387a86b9d1d57802b77f21b83 neinp/example_server_test.go -rw-r--r-- 434 bytes
b441da6dRuben Schuller initial commit 2 years ago
                                                                                
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
package neinp_test

import (
	"github.com/rbns/neinp"
	"fmt"
	"net"
)

func ExampleServer() {
	fs := &neinp.NopP2000{}

	l, err := net.Listen("tcp", "localhost:9999")
	if err != nil {
		fmt.Println("listen:", err)
		return
	}

	for {
		c, err := l.Accept()
		if err != nil {
			fmt.Println("accept:", err)
			return
		}

		s := neinp.NewServer(fs)
		if err := s.Serve(c); err != nil {
			fmt.Println("serve:", err)
			return
		}
	}
}