nil) let connection = NWConnection(to: server, using: .tcp) connection.stateUpdateHandler = { (newState) in switch newState { case .ready: // can send data break default: // error, waiting, disconnected break } } connection.start(queue: q) let listener = try NWListener(using: .tcp) listener.service = NWListener.Service(name: "yllan", type: "_bicycle._tcp") listener.newConnectionHandler = { (newConnection) in newConnection.stateUpdateHandler = { (newState) in switch newState { case .ready: // can read break default: break } } newConnection.start(queue: q) } listener.start(queue: q)