From 6ef0d6f1a5d1f0afd4ede69cb757e14289dbd64a Mon Sep 17 00:00:00 2001 From: Zorchenhimer Date: Sat, 23 Mar 2019 16:09:47 -0400 Subject: [PATCH] Add some debugging info to the client connection --- chatroom.go | 1 + connection.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/chatroom.go b/chatroom.go index 3744f75..d62fe99 100644 --- a/chatroom.go +++ b/chatroom.go @@ -96,6 +96,7 @@ func (cr *ChatRoom) Join(name, uid string) (*Client, error) { } } + conn.clientName = name client := &Client{ name: name, conn: conn, diff --git a/connection.go b/connection.go index b09ac79..715b412 100644 --- a/connection.go +++ b/connection.go @@ -12,6 +12,7 @@ type chatConnection struct { *websocket.Conn mutex sync.RWMutex forwardedFor string + clientName string } func (cc *chatConnection) ReadData(data interface{}) error { @@ -29,7 +30,10 @@ func (cc *chatConnection) WriteData(data interface{}) error { stats.msgOutInc() err := cc.WriteJSON(data) if err != nil { - return fmt.Errorf("Error writing data to %s: %v", cc.Host(), err) + if operr, ok := err.(*net.OpError); ok { + fmt.Println("OpError: " + operr.Err.Error()) + } + return fmt.Errorf("Error writing data to %s %s: %v", cc.clientName, cc.Host(), err) } return nil }