开发者

CFRunLoopRun() problem

i had a problem on CFRunLoopRun()

and here is the code after clicking the button , it Stops in CFRunLoopRun() method for some time , can any one help me wat to do next...........

AND my MAIN Problem IS i Have to Connect With BOCA printer USing IP Address and Port Number , and I had Done Up to Sending Messages to The BOCA, but My problem how can i get return response , or how can i Know that i was connected to Printer , And the printing message should be send when my system and BOCA printer Should connect one NETWork Connection ........

-(IBAction)ConnectButtonPressed

{ if(isPrinterConnected == FALSE)

{ char print[] = "print"; /* Build our socket context; this ties the joke to the socket */ CFSocketContext CTX = { 0, print, NULL, NULL, NULL };

/* Create the server socket as a TCP IPv4 socket and set a callback */
/* for calls to the socket's lower-level connect() function */
TCPClient = CFSocketCreate(NULL, PF_INET, SOCK_STREAM, IPPROTO_TCP,
                           kCFSocketConnectCallBack, (CFSocketCallBack)ConnectCallBack, &CTX);
if (TCPClient == NULL)
{
}
else{

    /* Set the port and address we want to listen on */
    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));
    addr.sin_len = sizeof(addr);
    addr.sin_family = AF_INET;
    addr.sin_port = htons(PORT);
    //addr.
    //addr.sin_addr.s_addr = INADDR_ANY;
    addr.sin_addr.s_addr = htonl((((((10 << 8) | 0) << 8) | 0) << 8) | 204);

    CFDataRef connectAddr = CFDataCreate(NULL, (unsigned char *)&addr, sizeof(addr));

    CFSocketConnectToAddress(TCPClient, connectAddr, -1);
    CFRunLoopSourceRef sourceRef = CFSocketCreateRunLoopSource(kCFAllocatorDefault, TCPClient, 0);
    CFRunLoopAddSource(CFRunLoopGetCurrent(), sourceRef, kCFRunLoopCommonModes);
    CFRelease(sourceRef);
    CFRunLoopRun();
    NSLog(@"next line ");

//isPrinterConnected = TRUE;


//[connect setTitle: @"Disconnect" forState: UIControlStateNormal];
}

}else 

{ close(sock); isPrinterConnected = FALSE; [myBut开发者_如何学Goton setTitle: @"Connect" forState: UIControlStateNormal]; }

}


With CFRunLoopRun you tell the iOS to stop executing the code and run everything explicitly which is scheduled in the runloop. This is a blocking call, it will only return if a code which is executed IN the runloop calls CFRunLoopStop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜