Tearing down a DO connection
Tearing down a DO connection
- Subject: Tearing down a DO connection
- From: email@hidden
- Date: Mon, 7 Oct 2002 22:39:25 -0400
All:
I am trying to tear down a DO connection that was established, and I
am finding that I can't quite get everything released. Here's how I am
setting up the connection:
tcpPort = [[NSSocketPort alloc] initRemoteWithTCPPort:kTCPPort_
host:@"127.0.0.1"];
if (nil == tcpPort)
{
NSLog(@"Couldn't find connection on host");
return;
}
NS_DURING
connection = [[NSConnection alloc]
initWithReceivePort:(NSPort*)[[tcpPort class] port]
sendPort:tcpPort];
proxy = [connection rootProxy];
NS_HANDLER
NSLog(@"ERROR %@", [localException description]);
proxy = nil;
NS_ENDHANDLER
if (nil == proxy)
{
NSLog(@"couldn't open connection");
return;
}
[proxy setProtocolForProxy:@protocol(PokerProtocol)];
otherPlayer = (PokerController*)proxy;
[otherPlayer acceptConnection:self];
[otherPlayer retain];
if (otherPlayer)
connectionState = kConnected_;
And to release the object/connection:
// Clean up the player
if (connectionState != kCloseRequest_)
{
NSLog(@"Requesting close");
[otherPlayer requestClose];
}
// Clean up the DO
[otherPlayer release];
otherPlayer = nil;
[connection invalidate];
[connection release];
[tcpPort invalidate];
[tcpPort release];
// Clean up the connection state
connectionState = kNone_;
Now, when I run 2 copies of the application I can have one be the
server, open/close the connection as many times as I would like, and
have the connection work correctly. But if I quit the original server,
and then have the original client wait for a connection, it gets the
following error:
2002-10-07 22:28:49.480 PokerServer[3054] ERROR [NSPortCoder
sendBeforeTime:sendReplyPort:] timed out
This leads me to believe that the NSTCPPort hasn't been closed
correctly (like if you don't close your sockets correctly). Am I on
the right track, does anyone have any ideas about what I'm doing
wrong?!?
Thanks in advance.
Jeremy Faller
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.