2
我在特定端口上接收消息時遇到問題。發送工作正常。接收UDP消息
的代碼看起來像這樣:
import Foundation
import CocoaAsyncSocket
class InSocket: NSObject, GCDAsyncUdpSocketDelegate {
//let IP = "192.168.1.196"
let PORT:UInt16 = 14000
var isocket:GCDAsyncUdpSocket!
override init(){
super.init()
setupConnection()
}
func setupConnection(){
isocket = GCDAsyncUdpSocket(delegate: self, delegateQueue: DispatchQueue.main)
do{
try isocket.bind(toPort:PORT)
try isocket.beginReceiving()
} catch {print("ErrorReceive")}
}
func udpSocket(sock: GCDAsyncUdpSocket!, didReceiveData data: NSData, fromAddress address: NSData!, withFilterContext filterContext: AnyObject!) {
let str = NSString(data: data as Data, encoding: String.Encoding.ascii.rawValue)
print(str)
}
}
我網的統計數據看到,應用程序接收數據包: Packets
但我沒有看到一個控制檯東西。 有些想法?
我遇到問題了,你解決了嗎? –