Note that there are some explanatory texts on larger screens.

plurals
  1. POclient side on MAC OS X gets empty responses (using BSD sockets and Cocoa's NSFileHandle)
    text
    copied!<p>I'm connecting a linux machine (acting as server) and a Mac machine (as the client) using bsd sockets. Because of Cocoa's improve I'm setting bsd sockets the usual way but then encapsulating it on a NSFileHandle object. I'm using this object to send and receive messages from the server. </p> <p>The protocol goes as follow: Linux gets a message from the Mac, and immediately echoes that message back to Mac. </p> <p>Everything goes well 'till I get the message back. My mac gets the message empty. </p> <p>Here is what I do, when sending the message.</p> <pre><code>const char *toSend = [line cStringUsingEncoding:NSASCIIStringEncoding]; printf("message to send %s\n", toSend); //[self writeData:[line dataUsingEncoding: encoding]]; [self writeData:[NSData dataWithBytes:toSend length:strlen(toSend)]]; [self readInBackgroundAndNotify]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:observer selector:@selector(process:) name:NSFileHandleReadCompletionNotification object:self]; </code></pre> <p>As you can see I set "process" on "observer" to process the server respond. this method does the following.</p> <pre><code>NSFileHandle *fh = [notification object]; NSData *data = [fh availableData]; NSString *dataString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; printf("server says %s\n", [dataString cStringUsingEncoding:NSASCIIStringEncoding]); [dataString release]; </code></pre> <p>On console I get: "server says " and that's all</p> <p>On the Linux side I'm printing what I get, and before sending it back I check I there's something. </p> <p>I know I can use bsd regular sockets on Mac but I really want to pull this of.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload