i avait un problème CFRunLoopRun() sur CFRunLoopRun()problème
et est ici le code après avoir cliqué sur le bouton, il arrête la méthode CFRunLoopRun() pendant un certain temps, peut me aider wat à faire et ... mon problème principal est que je dois me connecter avec l'imprimante BOCA en utilisant l'adresse IP et le numéro de port, et j'ai dû envoyer des messages à la BOCA, mais mon problème comment puis-je obtenir une réponse de retour, ou comment puis-je savoir que je suis connecté à l'imprimante, et le message d'impression doit être envoyé lorsque mon système et l'imprimante BOCA doivent se connecter une connexion NETWork ........
- (IBAction) ConnectButtonPressed
{if (isPrinterConnected == FAUX)
{print char [] = "print"; /* Construire notre contexte de socket; ceci lie la blague à la 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 (chaussette); isPrinterConnected = FALSE; [myButton setTitle: @ "Connect" forState: UIControlStateNormal]; }
}
Comme je suis nouveau dans le développement de l'application, je ne connais pas tous ces ........ – nikey