#import "NSObjectGCDAsyncSocket.h" @implementation NSObjectGCDAsyncSocket { GCDAsyncSocket* socket; } /** * 单例 * * @return */ +(NSObjectGCDAsyncSocket *)defaultSocket { //socket只会实例化一次 static NSObjectGCDAsyncSocket* socket=nil; //保证线程安全,defaultSocket只执行一次 static dispatch_once_t once; dispatch_once(&once, ^ { socket=[[NSObjectGCDAsyncSocket alloc] init]; }); return socket; } /** * 初始化 * * * @return self */ -(instancetype)init { self=[super init]; if (self) { socket=[[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)]; } return self; }