Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化 & bug修改 #17

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions examples/mock/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (c *ClientDemo) Start(userID, protocol, addr string) {
err := cli.Connect(addr)
if err != nil {
logger.Error(err)
return
}
count := 10
go func() {
Expand All @@ -61,7 +62,7 @@ func (c *ClientDemo) Start(userID, protocol, addr string) {
continue
}
recv++
logger.Warnf("%s receive message [%s]", cli.ServiceID(), frame.GetPayload())
logger.Infof("%s receive message [%s]", cli.ServiceID(), frame.GetPayload())
if recv == count { // 接收完消息
break
}
Expand All @@ -76,8 +77,12 @@ type WebsocketDialer struct {

// DialAndHandshake DialAndHandshake
func (d *WebsocketDialer) DialAndHandshake(ctx kim.DialerContext) (net.Conn, error) {
logger.Info("start ws dial: ", ctx.Address)
// 1 调用ws.Dial拨号
conn, _, _, err := ws.Dial(context.TODO(), ctx.Address)
ctxWithTimeout, cancel := context.WithTimeout(context.TODO(), ctx.Timeout)
defer cancel()

conn, _, _, err := ws.Dial(ctxWithTimeout, ctx.Address)
if err != nil {
return nil, err
}
Expand All @@ -96,7 +101,7 @@ type TCPDialer struct {

// DialAndHandshake DialAndHandshake
func (d *TCPDialer) DialAndHandshake(ctx kim.DialerContext) (net.Conn, error) {
logger.Info("start dial: ", ctx.Address)
logger.Info("start tcp dial: ", ctx.Address)
// 1 调用net.Dial拨号
conn, err := net.DialTimeout("tcp", ctx.Address, ctx.Timeout)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion examples/mock/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ func (h *ServerHandler) Accept(conn kim.Conn, timeout time.Duration) (string, ki

// Receive default listener
func (h *ServerHandler) Receive(ag kim.Agent, payload []byte) {
logger.Infof("srv received %s", string(payload))
_ = ag.Push([]byte("ok"))
}

// Disconnect default listener
func (h *ServerHandler) Disconnect(id string) error {
logger.Warnf("disconnect %s", id)
logger.Infof("disconnect %s", id)
return nil
}
2 changes: 1 addition & 1 deletion websocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (c *Client) Close() {
})
}

// Read a frame ,this function is not safey for concurrent
// Read a frame ,this function is not safely for concurrent
func (c *Client) Read() (kim.Frame, error) {
if c.conn == nil {
return nil, errors.New("connection is nil")
Expand Down