This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package main
import "net"
// MockServer 开启一个TCP监听,并从accept的连接上循环读取数据
type MockServer struct {
l net.Listener
}
func (ms *MockServer) start(addr string) (err error) {
ms.l, err = net.Listen("tcp", addr)
if err != nil {
return err
go func() {
for {
conn, err := ms.l.Accept()
//fmt.Println(err)
return
buf := make([]byte, 8)
_, err = conn.Read(buf)
}()
func (ms *MockServer) stop() {
ms.l.Close()