#import <sys/socket.h>
#import <netinet/in.h>
#import <arpa/inet.h>
我已经导入了上面的标题,但是
setsockopt(CFSocketGetNative(TCPSocket), SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
显示警告“使用未声明的标识符‘TCPSocket’”;我需要导入其他头文件吗?
添加:
CFSocketContext CTX = {0,self,NULL,NULL,NULL};
_socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, kCFSocketConnectCallBack, TCPServerConnectCallBack, &CTX);
setsockopt(CFSocketGetNative(_socket), SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
我用_socket代替了TCPSocket。