• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Obtaining port from NSSocketPort
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Obtaining port from NSSocketPort (From: Charles Françoise <email@hidden>)

  • Prev by Date: Re: [NEWBIE]: Scrolling windows
  • Next by Date: Re: objectForKey
  • Previous by thread: Obtaining port from NSSocketPort
  • Next by thread: Reading binary files
  • Index(es):
    • Date
    • Thread