Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nooshva

macrumors newbie
Original poster
Sep 17, 2008
4
0
Im having one issue that is rather big with using CFSockets in a Server side app --> The code for accepting sockets is as follows

Code:
void SocketCallBack (CFSocketRef s,CFSocketCallBackType callbackType,CFDataRef address,const void *data,void *info) {
	switch (callbackType) {
		case kCFSocketAcceptCallBack:
			printf("SocketCallBack -> Type of kCFSocketAcceptCallBack\n");
			struct sockaddr_in * theName = (struct sockaddr_in *) CFDataGetBytePtr(address);
			CFSocketRef aSocket = CFSocketCreateWithNative(kCFAllocatorDefault,(CFSocketNativeHandle) data,kCFSocketDataCallBack, SocketCallBack,NULL);
			if (aSocket) {
				printf("Native Socket Created Successfully From Location: %s, Adding to Run Loop for Listening Data\n", inet_ntoa(theName->sin_addr));
				CFRunLoopAddSource(CFRunLoopGetCurrent(),CFSocketCreateRunLoopSource(NULL, aSocket, 0),kCFRunLoopDefaultMode);
			}
			break;
		case kCFSocketDataCallBack:
			printf("SocketCallBack -> Type of kCFSocketDataCallBack\n");
			
			if (CFDataGetLength(data) <= 0) {
				printf("Disconnected!");
				CFSocketInvalidate(s);
				break;
			}
			
			printf("Data Callback Data -> %s\n",CFDataGetBytePtr(data));
			break;
		default:
			printf("SocketCallBack -> Type of UNKNOWN - ID: %i\n", callbackType);
			break;
	}
	
}

Everything works fine except for the Client socket callback. (I.E. Connects to server fine) It's not doing a callback when any data is in the buffer. Any Ideas?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.