 
 let INETADDRESS_ANY = in_addr(s_addr: 0)
 
-//var sockAddress = sockaddr_in(
-//    sin_len:    __uint8_t(sizeof(sockaddr_in)),
-//    sin_family: sa_family_t(AF_INET),
-//    sin_port:   htons(4242),
-//    sin_addr:   in_addr(s_addr: 0),
-//    sin_zero:   ( 0, 0, 0, 0, 0, 0, 0, 0 )
-//)
-
-var responseSource: DispatchSourceRead? //dispatch_source_t?
+var responseSource: DispatchSourceRead?
+typealias SocketFd = Int32
+
+func getSocket(address: String, port: UInt16) -> (sockaddr_in, SocketFd)? {
+    
+    var sockAddress = sockaddr_in(
+        sin_len:    __uint8_t(MemoryLayout<sockaddr_in>.size),
+        sin_family: sa_family_t(AF_INET),
+        sin_port:   port.bigEndian,
+        sin_addr:   in_addr(s_addr: 0),
+        sin_zero:   ( 0, 0, 0, 0, 0, 0, 0, 0 )
+    )
+    
+    /// inet_pton turns a text presentable ip to a network/binary representation
+    _ = address.withCString({ cs in inet_pton(AF_INET, cs, &sockAddress.sin_addr) })
+
+    /// A socket file descriptor
+    let sockFd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)
+    
+    guard sockFd >= 0  else {
+        print("Error: Could not create socket. \(String(cString: strerror(errno)))")
+        return nil
+    }
+
+    return (sockAddress, sockFd)
+}
 
 func receiver(address: String, port: UInt16) -> DispatchSourceRead? {
     /**

        print("Error: Could not bind socket! \(errmsg)")
        return nil
    }
    
    /// Connect. Since we're using UDP this isn't actually a connection but it does save us
    /// from having to restate the address when we want to use the socket.
    
/** 
    Enabling this causes the server to not receive any messages and appears to dump/deny any
    connections on the sockFd because when attempting to connect to it via the
    

    the server, whereas when we don't call connect the nc command stays active and allows 
    subsequent messages to be sent.
    This issue took a good while to discover. :(

    
    let connectSuccess = withUnsafePointer(&sockAddress) {
        connect(sockFd, UnsafePointer($0), socklen_t( sizeofValue(sockAddress)))
    }
    guard connectSuccess == 0 else {
        let errmsg = String.fromCString(strerror(errno))    
        print("Could not connect! \(errmsg)")
        return nil
    }
*/
    /// Create a GCD thread that can listen for network events.
    let newResponseSource = DispatchSource.makeReadSource(fileDescriptor: sockFd)
    
