GCDAsyncUdpSocket绑定错误

时间:2018-06-21 19:51:43

标签: gcdasyncudpsocket

我在我的应用程序中使用CocoaAsyncSocket框架来处理UDP套接字。一切正常,但最后一次出现错误消息,“绑定错误:不允许操作”。 enter image description here 但是,我的应用程序正常运行。我可以接收和发送数据。有人知道出什么事了吗?

class ServerUDP: NSObject, GCDAsyncUdpSocketDelegate {
    weak var delegate: ServerUDPDelegate?

    let IP = "255.255.255.255"
    let PORT:UInt16 = 6454
    var socket:GCDAsyncUdpSocket!

    override init() {
        super.init()
        setupConnection()
    }

    func setupConnection(){
        //            var error: NSError?
        socket = GCDAsyncUdpSocket(delegate: self, delegateQueue: DispatchQueue.main)

        do {
            try socket.bind(toPort: PORT)
        }
        catch {
            print("Binding error: ", error.localizedDescription)
        }
        do {
            try socket.beginReceiving()
        }
        catch {
            print("Connecting error: ", error.localizedDescription)
        }
        do {
            try socket.enableBroadcast(true)
        }
        catch {
            print("brodcust error: ", error.localizedDescription)
        }

    }

0 个答案:

没有答案