             throw TCPError.unknown(description: "Port was not defined in URI")
         }
         socket = tcpconnect(try IP(remoteAddress: host, port: port).address, never)
+        if let socket = self.socket {
+            if socket == nil {
+                throw TCPError.closedSocket(description: "Unable to connect.")
+            }
+            else {
+                closed = false
+            }
+        }
     }
-    
-    
-    public func receive(max byteCount: Int) throws -> C7.Data {
-        return try receive(upTo: byteCount, timingOut: never)
+
+    public func send(data: C7.Data) throws {
+        try send(data, flushing: false, deadline: never)
     }
-    
-    public func send(data: C7.Data) throws {
-        try send(data, flushing: true, deadline: never)
-    }
-    
+
     public func flush() throws {
         try flush(timingOut: never)
     }

import C7

public final class TCPConnection: C7.Connection {
    
    public var uri: C7.URI
    var socket: tcpsock?
    public private(set) var closed = false

    public init(to uri: C7.URI) throws {
        self.uri = uri
    }
    
    public func open() throws {
        guard let host = uri.host else {
            throw TCPError.unknown(description: "Host was not defined in URI")

        tcpclose(socket)
        return true
    }

    func getSocket() throws -> tcpsock {
        guard let socket = self.socket else {
            throw TCPError.closedSocket(description: "Connection has not been initialized. You must first open to the connection.")
        }
        if socket == nil {
            throw TCPError.closedSocket(description: "Connection has not been initialized. You must first open to the connection.")
        }
        return socket
    }

    func assertNotClosed() throws {
        if closed {
            throw TCPError.closedSocketError
        }
    }

    deinit {
        if let socket = socket where !closed {
            tcpclose(socket)
