Question

#import <sys/socket.h>
#import <netinet/in.h>
#import <arpa/inet.h>

I have import the headers above,but

setsockopt(CFSocketGetNative(TCPSocket), SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));

show warnings "use of undeclared identifier 'TCPSocket'";do I need to import other header files?

add:

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));

I have insteaded TCPSocket of _socket.

Was it helpful?

Solution

What is TCPSocket here? It is supposed to a variable of type CFSocketRef. It looks like you need to set that up first. Post more code and maybe we can be of more help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top