I try to create a socket as shown below:
socket = GCDAsyncSocket(delegate: self, delegateQueue: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0))
and I implement the func:
func socket(socket : GCDAsyncSocket, didConnectToHost host:String, port p:UInt16){
pingTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "sendPing:", userInfo: nil, repeats: true)
}
func sendPing(){
print("will send ping...")
}
But the sendPing
will never be called, and if I try this:
socket = GCDAsyncSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
the deletegateQueue
is socket = GCDAsyncSocket(delegate: self, delegateQueue: dispatch_get_main_queue())
, it will work fine.
The UI updating is use main queue, so I want to do socket connection with another type queue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)
seems to be a good one.
How can I make it work well?