我正在尝试使用SwiftSockets将数据从Mac发送到iPhone。
当我尝试以下代码时
var socket = UDPClient(address: "192.168.1.158", port: 20777)
override func viewDidLoad() {
super.viewDidLoad()
let res = socket.send(data: [255])
print(res.error.debugDescription)
}
我收到消息Optional(SwiftSocket.SocketError.unknownError)
,但没有收到来自iPhone的任何数据。
问题是什么,我该如何解决?
编辑:如果我尝试使用设备的主机名,则会收到以下消息
2018-08-27 01:28:01.893463+0100 App Name[863:10545] dnssd_clientstub ConnectToServer: connect()-> No of tries: 1
2018-08-27 01:28:02.894593+0100 App Name[863:10545] dnssd_clientstub ConnectToServer: connect()-> No of tries: 2
2018-08-27 01:28:03.894872+0100 App Name[863:10545] dnssd_clientstub ConnectToServer: connect()-> No of tries: 3
2018-08-27 01:28:04.895240+0100 App Name[863:10545] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:4 Err:-1 Errno:1 Operation not permitted