views:

207

answers:

0

Hello, I have a problem I created this client connects to a server and then want to send and receive strings (this is not implemented yet). When creating the connection I have a problem since the creation of the connection does not do "CFRunLoopRun ();"( tested by degbug). Someone any idea? Thank you.

- (void) acceptConnection:(int)fd { }  

static void AcceptCallback(CFSocketRef s, CFSocketCallBackType type, CFDataRef address,const void *data, void *info)

     {
                ClientVistaController *  obj;


            #pragma unused(type)
            assert(type == kCFSocketAcceptCallBack);
        #pragma unused(address)
            assert(data != NULL);

            obj = (ClientVistaController*) info;
            assert(obj != nil);

        #pragma unused(s)


            [obj acceptConnection:*(int *)data];


        }


-(void)startConnection
        {
            int port = [fieldPorta.text     intValue];



    CFSocketRef s = CFSocketCreate(NULL, 
                                       PF_INET, 
                                       SOCK_STREAM, 
                                       IPPROTO_TCP, 
                                       kCFSocketDataCallBack,
                                       AcceptCallback, 
                                       NULL);


        CFDataRef address;
        struct sockaddr_in sin;
        CFRunLoopSourceRef source;


        memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;
        sin.sin_port = htons(port);


        address = CFDataCreate(NULL, (unsigned char*)&sin, sizeof(sin));
        CFSocketConnectToAddress(s, address, 0);
        CFRelease(address);


        source = CFSocketCreateRunLoopSource(NULL, s, 0);

        CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);

        CFRelease(source);

        CFRelease(s);

        CFRunLoopRun();




    }



-(IBAction)Connetti

    {
                [self   startConnection];

            }