去除TCP服务端连接

This commit is contained in:
jixishi
2024-04-26 11:55:26 +08:00
parent d19c09e4cd
commit e3415ae05a
3 changed files with 14 additions and 54 deletions
-34
View File
@@ -24,7 +24,6 @@ type FoeWardMode int
const (
NOT FoeWardMode = iota
TCPS
TCPC
UDPC
)
@@ -43,41 +42,8 @@ func setForWardClient() (conn net.Conn) {
if err != nil {
log.Fatal(err)
}
default:
panic("未知模式设置")
}
return conn
}
func setForWardServer() {
switch FoeWardMode(config.forWard) {
case TCPS:
listen, err := net.Listen("tcp", config.address)
if err != nil {
log.Fatal(err)
}
for {
conn, err := listen.Accept() // 监听客户端的连接请求
if err != nil {
log.Println("Accept() failed, err: ", err)
continue
}
go process(conn) // 启动一个goroutine来处理客户端的连接请求
}
default:
panic("未知模式设置")
}
}
func process(conn net.Conn) {
defer conn.Close() // 关闭连接
//reader := bufio.NewReader(serialPort)
outs = append(outs, conn)
defer func() {
for i, w := range outs {
if w == conn {
outs = append(outs[:i], outs[i+1:]...)
}
}
}()
input(conn)
}