diff --git a/src/comm/comm.go b/src/comm/comm.go index a58cd6d..b68e7ec 100644 --- a/src/comm/comm.go +++ b/src/comm/comm.go @@ -27,6 +27,12 @@ func (c Comm) Connection() net.Conn { return c.connection } +// Close closes the connection +func (c Comm) Close() { + c.connection.Close() +} + + func (c Comm) Write(b []byte) (int, error) { c.connection.Write([]byte(fmt.Sprintf("%0.5d", len(b)))) n, err := c.connection.Write(b) diff --git a/src/recipient/recipient.go b/src/recipient/recipient.go index 1b2124c..652225a 100644 --- a/src/recipient/recipient.go +++ b/src/recipient/recipient.go @@ -178,6 +178,7 @@ func receive(forceSend int, serverAddress, serverTCP string, isLocal bool, c *we log.Error(err) return err } + defer tcpConnection.Close() } // await file @@ -329,7 +330,6 @@ func connectToTCPServer(room string, address string) (com comm.Comm, err error) if err != nil { return } - defer connection.Close() connection.SetReadDeadline(time.Now().Add(3 * time.Hour)) connection.SetDeadline(time.Now().Add(3 * time.Hour)) connection.SetWriteDeadline(time.Now().Add(3 * time.Hour)) diff --git a/src/sender/sender.go b/src/sender/sender.go index d8960da..3adf687 100644 --- a/src/sender/sender.go +++ b/src/sender/sender.go @@ -211,6 +211,7 @@ func send(forceSend int, serverAddress, serverTCP string, isLocal bool, c *webso log.Error(err) return } + defer tcpConnection.Close() buffer = make([]byte, models.TCP_BUFFER_SIZE/2) } @@ -306,11 +307,10 @@ func connectToTCPServer(room string, address string) (com comm.Comm, err error) if err != nil { return } - defer connection.Close() connection.SetReadDeadline(time.Now().Add(3 * time.Hour)) connection.SetDeadline(time.Now().Add(3 * time.Hour)) connection.SetWriteDeadline(time.Now().Add(3 * time.Hour)) - + com = comm.New(connection) ok, err := com.Receive() if err != nil {