Re: connection when invalid while waiting for a reply
Re: connection when invalid while waiting for a reply
- Subject: Re: connection when invalid while waiting for a reply
- From: "William Irving Zumwalt" <email@hidden>
- Date: Wed, 27 Dec 2006 16:55:25 -0600
Sorry. The error is displayed in the console output (run log). It
occurs after the thread has started up.
Here is the code I use to start a thread. Basically I got the code
from a book and a few examples on the web.
---
- (void)launchServerThreads
{
[MyServer startNetworkThreadWithTag:0 forController:self];
}
+ (NSConnection *)startNetworkThreadWithTag:(int)theTag
forController:(id <NetworkController>)controller
{
// Ports used for communications between the threads.
NSPort *port1 = [NSPort port];
NSPort *port2 = [NSPort port];
// The port that is a receive port for the main thread needs to be the
// send port for the new thread and vice-versa.
NSArray *portArray = [NSArray arrayWithObjects:port2, port1,
[NSNumber numberWithInt:theTag], nil];
NSConnection *connection = [[NSConnection alloc]
initWithReceivePort:port1 sendPort:port2];
[connection setRootObject:controller];
// Our new thread.
[NSThread detachNewThreadSelector:@selector(connectWithPorts:)
toTarget:self withObject:portArray];
return connection;
}
+ (void)connectWithPorts:(NSArray *)portArray
{
BOOL local_debug = NO;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NetworkServer *instance = [[self alloc] init];
NSConnection *connection = [[NSConnection alloc]
initWithReceivePort:[portArray objectAtIndex:0]
sendPort:[portArray objectAtIndex:1]];
int serverTag = [[portArray objectAtIndex:2] intValue];
[connection setRootObject:instance];
// Notify controller that comm channels are now open.
[(id <NetworkController>)[connection rootProxy]
setServer:instance tag:serverTag];
if (local_debug) {
NSMutableDictionary *threadDictionary =
[[NSThread currentThread] threadDictionary];
NSLog(@"Thread dictionary:\n%@\n", [threadDictionary description]);
}
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
} while ([instance isRunning]);
[[connection receivePort] invalidate];
[[connection sendPort] invalidate];
[connection release];
[instance release];
[pool release];
}
On 12/27/06, John Stiles <email@hidden> wrote:
Please be more specific. Does this error show up on your console? Is
it the return value from a function? Is the thread not starting up?
On Dec 27, 2006, at 2:47 PM, William Irving Zumwalt wrote:
> I'm working with threads and after lauching a thread, I get an error
> "connection went invalid while waiting for a reply".
>
> What exactly does this mean (other than my ports are invalid)?
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> 40blizzard.com
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden