Unable to connect with IPv6 socket (Modified by Shaun Wexler)
Unable to connect with IPv6 socket (Modified by Shaun Wexler)
- Subject: Unable to connect with IPv6 socket (Modified by Shaun Wexler)
- From: Shaun Wexler <email@hidden>
- Date: Fri, 10 Oct 2003 10:45:47 -0700
- Resent-date: Fri, 10 Oct 2003 11:31:59 -0700
- Resent-from: Shaun Wexler <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: email@hidden
I've added a Remote Control plug-in to my app, and it functions
properly, except it fails when trying to connect using an AF_INET6
sockaddr (a NSSocketPort passed to a NSConnection). Here is the code
that fails with IPv6 (within the exception handling block), but works
perfectly with IPv4:
// NOTE: hostRemoteAddress is an NSData containing a 28-byte IPv6
sockaddr struct, which is
// returned from a resolved NSNetService.
hostRemoteSocketPort = [[NSSocketPort alloc]
initRemoteWithProtocolFamily:protocolFamily socketType:SOCK_STREAM
protocol:IPPROTO_TCP address:hostRemoteAddress];
if (hostRemoteSocketPort)
{
struct sockaddr *socketAddress = (struct sockaddr
*)[[hostRemoteSocketPort address] bytes];
if (socketAddress) {
protocolFamily = socketAddress->sa_family;
if (protocolFamily == AF_INET) {
remotePort = ((struct sockaddr_in *)socketAddress)->sin_port;
} else if (socketAddress->sa_family == AF_INET6) {
remotePort = ((struct sockaddr_in6 *)socketAddress)->sin6_port;
} else {
remotePort = NULL;
}
if (remotePort)
{
hostRemoteConnection = [[NSConnection alloc] initWithReceivePort:nil
sendPort:hostRemoteSocketPort];
if (hostRemoteConnection)
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(connectionDidDie:)
name:NSConnectionDidDieNotification object:hostRemoteConnection];
hostRemoteProxy = [hostRemoteConnection rootProxy]; /*** throws
here ***/
if (hostRemoteProxy)
{
NSLog(@"remote - connected to \"%@\" (%@) with TCP/%@ port #%u",
hostComputerName, [hostRemoteProxy fullUserName], protocolFamily ==
AF_INET ? @"IP" : @"IPv6", remotePort);
[hostRemoteProxy retain];
if (connectTimeoutTimer) {
[connectTimeoutTimer invalidate];
connectTimeoutTimer = nil;
}
[[NSNotificationCenter defaultCenter]
postMainThreadNotificationName:@"SKWRemoteHostDidConnectNotification"
object:self];
}
}
}
}
}
It throws "NSPortTimeoutException: [NSPortCoder
sendBeforeTime:sendReplyPort:] timed out" when attempting to get the
rootProxy.
And ideas what I'm doing wrong? I've forced the address to an IPv6 to
test the code, and fortunately, NSNetService never fails to return an
IPv4, so the failure is unlikely to arise, but I want to fix it.
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
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.