Re: Tearing down a DO connection
Re: Tearing down a DO connection
- Subject: Re: Tearing down a DO connection
- From: Guy Winslow <email@hidden>
- Date: Tue, 8 Oct 2002 09:59:15 -0700
Usually in socket type logic the client has to close the connection and
the Server releases the Thread after the client socket is closed. I
use to send Message to clients telling them server is going down and
they should shutdown there connections. At with point all sockets are
cleared you can clean up server. otherwise you wont be able to cleanup
sockets that are open, and other end will stay open till errors out.
You may be doing this and i am not seeing it. But check that out and
see if it helps.
On Monday, October 7, 2002, at 07:39 PM, email@hidden wrote:
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.
_______________________________________________
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.