- (Void) readStream {
char buffer [64];
ssize_t nRet = 0;
do {
nRet = recv (CFSocketGetNative (_socket), buffer, sizeof (buffer), 0); / / read data
the sending end from the socket bufferif (nRet == 0 | | nRet == -1) {/ / server exits or off
/ / Jump reminder box
UIAlertView * alert = [! [UIAlertView alloc] initWithTitle: @ "" message: @ "Server has been turned down" delegate: nil cancelButtonTitle: @ "Close" otherButtonTitles: nil];
[Alert show];
[Alert release];
close (CFSocketGetNative (_socket)); / / close the socket
[Self doConnect]; / / reconnect
}
} While (nRet = 0 && nRet = -1!!);
}
The problem here is that only even twice, after the first successful connection, the server exits, there are tips: "! Server has been turned down", and then re-open the server, a second connection, can connect successfully The server can receive data. The second disconnect the server, the client is not prompted. Then open the server, but the client can not receive the data given. Client then sends data twice, to take the initiative to quit. Here's a Bug, it should be a problem with my logic, but I am looking for a long time, did not find out.
I do not know will not be a problem with the send function? Because it is a keyboard, to achieve the function of self-portraits are as follows: For example, to send a letter A
- (IBAction) sendA: (id) sender {
Requirements on keyboard events / / server format k_0_65k_2_65, after a server to resolve, in the letter A
WindowsNSString * stringToSend = [NSString stringWithFormat: @ "k_0_65k_2_65"];
const char * data = [stringToSend UTF8String];
if (Socket! = nil) {
send (CFSocketGetNative (Socket), data, strlen (data) +1, 0);
}
}
Please take a look at passing, help, thank you
Reply:
Confirm each Socket closed every time, resources freed up.
Reply:
I had a useful
/ / Automatic release mechanism; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init][Pool release];
Be still the same bug, there is my side think so, as long as my server is not disconnected, then I would not have re-connected, you can do the appropriate revc and send operations, a disconnect, I'll close the socket re doConnect, was established in doConnect function socket inside. They still feel right. Patch bug really too bothered, because I have been at the original repair my thoughts above, it has been up not on, there should be wrong with my logic. Hope pointing twelve! Thank you
Reply:
Or is not the sending and receiving of every cycle of creation and should be closed socket? In that case, I was not put socket creation function on and off when the function is separated, then the appropriate call?
Reply:
Khan is really no need to think too much ~
Reply:
I'll end this post, huh.
Reply:
Well - you upstairs myself, haha
Reply:
Learn! ! ! !
Reply:
No comments:
Post a Comment