Re: Obtaining port from NSSocketPort
Re: Obtaining port from NSSocketPort
- Subject: Re: Obtaining port from NSSocketPort
- From: Dustin Voss <email@hidden>
- Date: Fri, 15 Oct 2004 12:18:12 -0700
On 15 Oct, 2004, at 8:59 AM, Charles Françoise wrote:
I created a NSSocketPort using :
mySocketPort = [[NSSocketPort alloc] initWithTCPPort:0];
this is supposed to use an arbitrary port. The problem is, I don't
know how to obtain the port that has been open.
[mySocketPort address] returns a NSData object but I don't know what
to do with it.
Help anyone ?
Are you aware that NSSocketPort is not really good for general socket
stuff? It is meant to be used with Distributed Objects. You are better
off using one of the third-party libraries at
<
http://cocoadev.com/?SocketClasses>, such as AsyncSocket (written by
yours truly).
That said, the NSData object returned by [mySocketPort address] could
be a sockaddr_in struct. If so, this code should work:
#import <netinet/in.h>
#import <arpa/inet.h>
- (UInt16) socketPort: (NSData *)address
{
struct sockaddr_in *pAddr = (struct sockaddr_in *) [address bytes];
return pAddr->sin_port;
}
_______________________________________________
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