diff --git a/cmd/iface/main.go b/cmd/iface/main.go index a64e02c..8d0baa6 100644 --- a/cmd/iface/main.go +++ b/cmd/iface/main.go @@ -21,7 +21,7 @@ func main(){ // if receive message -> send it back sender <- &msg - // sender <- nil + sender <- nil } diff --git a/ws/client.go b/ws/client.go index 7d7cd3e..32685fe 100644 --- a/ws/client.go +++ b/ws/client.go @@ -131,21 +131,21 @@ func (c *client) reader(){ } /* (2) Wait for available data */ - c.io.sock.SetReadDeadline(time.Now().Add(time.Microsecond*10)) - _, err := c.io.reader.Peek(1) + // c.io.sock.SetReadDeadline(time.Now().Add(10*time.Microsecond)) + // _, err := c.io.reader.Peek(1) - // timeout -> continune checking - if neterr, ok := err.(net.Error); ok && neterr.Timeout() { - continue + // // timeout -> continune checking + // if neterr, ok := err.(net.Error); ok && neterr.Timeout() { + // time.Sleep(10*time.Microsecond) + // continue + // } - } + // // another error -> stop reading + // if err != nil { + // break + // } - // another error -> stop reading - if err != nil { - break - } - - c.io.sock.SetReadDeadline(time.Time{}) // remove timeout + // c.io.sock.SetReadDeadline(time.Time{}) // remove timeout /* (3) Parse message */ msg, err := readMessage(c.io.reader) @@ -238,7 +238,7 @@ func (c *client) close(status MessageError){ Data: make([]byte, 8), } binary.BigEndian.PutUint16(msg.Data, uint16(status)) - msg.Data = append(msg.Data, []byte("Closing")...) + msg.Data = append(msg.Data, []byte(" close")...) msg.Size = uint( len(msg.Data) ) /* Send message */ @@ -247,6 +247,7 @@ func (c *client) close(status MessageError){ } /* (2) Close socket */ + c.io.sock.SetReadDeadline(time.Now()) time.Sleep(time.Second * 3) c.io.sock.Close()