Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CFSocketSendData -- what am I doing wrong?



Hi,

I have an application that is listening on a port via the following...
sender = CFSocketCreate(NULL, AF_INET, SOCK_STREAM, IPPROTO_TCP, clientCallbacks, myFunction, &context);
if (sender) {
struct sockaddr_in frameAddr;
frameAddr.sin_addr.s_addr = INADDR_ANY;
frameAddr.sin_port = ntohs(FramePort);
frameAddr.sin_family = AF_INET;


CFDataRef senderData = CFDataCreate(NULL, (const UInt8*) &frameAddr, sizeof(struct sockaddr_in));
if(CFSocketSetAddress(sender,senderData) != kCFSocketSuccess){
CFShow(CFSTR("false\rFailed to bind to the requested port."));
return;
}


// Schedule the run loop and add to the ref lists
FrameRunLoopSource = CFSocketCreateRunLoopSource(NULL, sender , 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), FrameRunLoopSource, kCFRunLoopCommonModes);
}


... and my function looks like this...
void myFunction(CFSocketRef s, CFSocketCallBackType type, CFDataRef address, const void * data, void *info)
{
static int connected;
CFSocketError err = kCFSocketError;
if (type==kCFSocketDataCallBack) {
SendVersion(s);


    }
}

... and SendVersion does this...

int success = 1;
    CFSocketError err = kCFSocketSuccess;
    CFDataRef Data = CFDataCreate(NULL, (const UInt8*)data, len);
    CFDataRef address = CFSocketCopyPeerAddress(s);

    CFShow(address);

    err= CFSocketSendData (s,NULL,Data,0.0);
    if (err==kCFSocketError) {
        CFShow(CFSTR("Socket error on send."));
        success = 0;
    }
    return success;

......

When I get into SendVersion, it always returns kCFSocketError, and no data is sent. Also, address is NULL at this point. What am I doing wrong?

Thanks,
-Chilton
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.