 
 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? {
     /**


func sender(address: String, port: UInt16) {
    
    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 file descriptor Int32
    let sockFd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)
    
    guard sockFd >= 0  else {
        let errmsg = String(cString: strerror(errno))
        print("Error: Could not create socket. \(errmsg)")
        return
    }

    let outData = Array("Greetings earthling".utf8)
    let addr = UnsafeMutablePointer<sockaddr_in>(&sockAddress)
    let ptrSockAddr = UnsafeMutablePointer<sockaddr>(OpaquePointer(addr))

    3) Connect the socket (optional).
    4) In a loop/separate thread/event listen for incoming packets.
    */
    
    /// 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.
    guard case (var sockAddress, let sockFd)? = getSocket(address: address, port: port) else { return nil }
    
    /// Bind the socket to the address
    let bindSuccess = withUnsafePointer(to: &sockAddress) {
