mirror of
https://github.com/lwch/natpass.git
synced 2024-04-21 12:41:54 +00:00
36 lines
542 B
Go
36 lines
542 B
Go
package handler
|
|
|
|
import (
|
|
"natpass/code/network"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/lwch/logging"
|
|
)
|
|
|
|
type client struct {
|
|
id string
|
|
c *network.Conn
|
|
}
|
|
|
|
func newClient(id string, conn *network.Conn) *client {
|
|
return &client{
|
|
id: id,
|
|
c: conn,
|
|
}
|
|
}
|
|
|
|
func (c *client) run() {
|
|
for {
|
|
msg, err := c.c.ReadMessage(time.Second)
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), "i/o timeout") {
|
|
continue
|
|
}
|
|
logging.Error("read message from %s: %v", c.id, err)
|
|
return
|
|
}
|
|
logging.Info("read message: %s", msg.String())
|
|
}
|
|
}
|