Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Intermittent message: [NSPortCoder sendBeforeTime:sendReplyPort:] timed out
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Intermittent message: [NSPortCoder sendBeforeTime:sendReplyPort:] timed out



I'm getting the above message intermittently (50% of the time, with repeated runs of success or failure) when trying to send messages to a remote object using distributed objects. The code used to set up the receiving socket is shown below, followed by the code used to send the message:

-(void)setupSocket { // Set up the receiver's socket

NSSocketPort *receivePort = nil;

NS_DURING
receivePort = [[NSSocketPort alloc] initWithTCPPort:SERVER_PORT];
NS_HANDLER
[receivePort release];
receivePort = nil;
NSLog(@"Error: Failed to bind to TCP port");
NS_ENDHANDLER

if (receivePort!=nil) {

serverConnection = [[NSConnection alloc] initWithReceivePort:receivePort sendPort:nil];
[receivePort release];

[serverConnection setDelegate:self];
[serverConnection setRootObject:self];
[[NSRunLoop currentRunLoop] addPort:receivePort forMode:NSConnectionReplyMode];

// Set a flag so that we can reuse the port immediately after releasing the socket object

{
int socket = [receivePort socket];
int flag = 1;

if (setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,(void*)&flag,sizeof(flag)) < 0)
NSLog(@"Failed to set socket address reuse");

if (setsockopt(socket,SOL_SOCKET,SO_REUSEPORT,(void*)&flag,sizeof(flag)) < 0)
NSLog(@"Failed to set socket port reuse");
}
}
}


-(IBAction)launchTESTOnRemoteServer:(id)sender { // Sends a message to a remote object

NSArray *selection = [serviceController selectedObjects];

if (selection == nil || [selection count]==0) return;

NSString *serverName = [[selection objectAtIndex:0] name];

NSLog(@"Lauching TEST on %@",serverName);

NSSocketPort *sendPort = [[NSSocketPort alloc] initRemoteWithTCPPort:SERVER_PORT host:serverName];

serverConnection = [[NSConnection alloc] initWithReceivePort:nil sendPort:sendPort];
[sendPort release];

id theProxy = [serverConnection rootProxy];

NSNumber *val = [NSNumber numberWithFloat:7.5]; // Autoreleased

[theProxy runTESTForClient:val];

}

I'm a complete newbie at this stuff, and have put this together from code fragments found various places. It's quite possible I'm not using the ports correctly. However it *does* work much of the time...

Thanks for any info,

Rick
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.