NSSocketPort vs. AF_UNIX?
NSSocketPort vs. AF_UNIX?
- Subject: NSSocketPort vs. AF_UNIX?
- From: Tom Harrington <email@hidden>
- Date: Tue, 30 Aug 2005 17:09:06 -0600
How can I get an NSSocketPort to use a Unix-domain socket transport?
The docs for NSSocketPort don't specify TCP/IP, only a "BSD socket",
so it would seem that this should be possible. Only I haven't been
able to get it to work.
On the server side I'm trying to set up the NSSocketPort with
-initWithProtocolFamily:socketType:protocol:address. So, family
AF_UNIX, check, socketType SOCK_STREAM, check, protocol PF_UNIX,
check. But "address" is described in the docs as "...family-specific
socket address for the receiver copied into an NSData object". What's
that?
I thought maybe it'd just be the path to the Unix-domain socket, and
that the other args would tell it enough to know what to do with it.
But passing this doesn't seem to work-- I just get nil returned for
the port:
NSString *addrString = @"/tmp/af_unix.test";
NSData *addrData = [remoteAddrString dataUsingEncoding:NSASCIIStringEncoding];
vendPort = [[NSSocketPort alloc] initWithProtocolFamily:AF_UNIX
socketType:SOCK_STREAM
protocol:PF_UNIX
address:addrData];
I also thought maybe I should set up a struct sockaddr_un, like I was
going to work directly with the socket, and then wrap up the struct in
an NSData:
struct sockaddr_un name;
memset(&name, 0, sizeof(struct sockaddr_un));
name.sun_family = AF_UNIX;
strcpy(name.sun_path, "/tmp/af_unix.test");
int len = sizeof(name.sun_family) + strlen(name.sun_path);
NSData *addrData = [NSData dataWithBytes:&name length:len];
But that didn't work any better.
I know how to work directly with Unix-domain sockets, I just can't
figure out what NSSocketPort wants from me here.
I can work around this on the server side by creating the socket
myself and then using
-initWithProtocolFamily:socketType:protocol:socket. That _seems_ to
work. But there's no comparable workaround for the client side.
--
Tom Harrington
email@hidden
AIM: atomicbird1
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden