I'm working with Siafnetvrk to create client applications for Aipiad, it is a small application, nothing Is fancy.
[This is how I make a connection to the server (running Windows)
- (void) {StartConnection four IP] = "192.168.0.244"; NSString * ipAddress = [[NSString alloc] initWithCString: IP]; / * Create our socket references; This socket * / CFSocketContext is an example of itself in CTX = {0, self, zero, zero, tap}; / * A TCP IPv4 create server socket as the socket and set a callback * / / * socket (to connect a call on the lower level) function * / TCPClient = CFSocketCreate (zero, PF_INET, SOCK_STREAM, IPPROTO_TCP, kCFSocketDataCallBack, ( CFSocketCallBack) Datacultack, and CTX); If (TCP Client == Faucet) Return; / * Set the port and address we would like to hear on * / struct sockaddr_in addr; Memeset (and adr., 0, size (ADR)); Addr.sin_len = sizeof (edit); Addr.sin_family = AF_INET; Addr.sin_port = htons (PORT); // PORT = 5001 addr.sin_addr.s_addr = inet_addr ([IP address UTF 8 string]); CFDataRef connectAddr = CFDataCreate (zero, (unsigned char *) and addr, sizeof (addr)); CFSocketConnectToAddress (TCPClient, connectAddr, -1); CFRunLoopSourceRef sourceRef = CFSocketCreateRunLoopSource (KCFAALOcteterDefault, TCPClient, 0); CFRunLoopAddSource (CFRunLoopGetCurrent (), sourceRef, KCFRun Loop Common Modes); CFRelease (sourceRef); CFRunLoopRun (); }
You can see, when I create server socket, I register to listen to incoming data from a callback server. In
Then I use CFRunLoopAddSource (. ..) and CFRunLoopRun () methods how it looks I send method this callback to listen in the background
Now, it's < / P>
-. (Zero) Send {if (TCP Client == Faucet) Return; Byte BitData [3]; For (Int i = 1; i
What I have to do is send commands to the server (3 bytes) array you would like to order) and to respond before sending server, the next order of this I set a wait to use the long, variable "receivedLastAnswer" is a flag when I DataCallBack method That's why, if Land server responds, the callback is invoked, it sets the flag on the right and when out and sent to the next command.
Of course it is not that I want to leave the code, just to test it and to see that it works, later I have to add another condition, a timeout situation, if The server does not respond perfectly
Now, my problem is that my application is not firing the customer, callback method, and in this way it only does chakras in infinitely; I think the reason for not firing the callback is because the application is busy in the time cycle, in fact if I remove the cycle, the callback is removed, but this does not make sense to me because the callback method is not It is believed to be running on a different thread and because it is running in a different thread, it should not make any difference whether the main thread is in a circle or I am completely misunderstood. Security that is how it works (that is not aimed at CFRunLoopRun ()?)
Also, I tried to use a time cycle, but a sleep () function, But this is the same, no callback has been removed.
Why do you have no idea or how can I complete it,
thanks. Well, I think callback will be called in my data if the main thread is busy or blocked, then I What he had to do was drop the callback method on the main pouch and put my sending method in the second thread, it actually worked very well, but I 'm styling I am wandering if there is no other way, but Now what do I need for this, so I stick it Sing
Comments
Post a Comment