[Problem] I am using GCDAsyncSocket for Tcp Socket processing. If I am in the main program, I can handle the callback of the result normally, but I want to encapsulate the Socket processing in a library, and complete the Socket initialization and The information is received and processed, but I find that I don’t know how to trigger the callback?
[Code]
If you process it directly in the main thread:
Initialization
GCDAsyncSocket *_socket;
_socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
Connect Connect
[self._tcpSocket connectToHost:deviceIp onPort:SERVERPORT error:&err]
At this time, the callback for successful connection can be triggered normally
-(void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
{
NSLog(@"didConnectToHost call");
}
But if I put the above process in the library and call it through the main program, then the didConnectToHost callback cannot be triggered
I think it’s because I don’t understand _socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; this delegate and delegateQueue. How should I deal with this place?
Thank you everyone
闭关修行中......