• 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: NSNetServiceBrowser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNetServiceBrowser


  • Subject: Re: NSNetServiceBrowser
  • From: Wolfgang Ante <email@hidden>
  • Date: Wed, 7 May 2003 17:46:04 +0200

Hi!

To get the host and port of a published service you found with...

- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser
didFindService:(NSNetService *)aNetService
moreComing:(BOOL)moreComing

...you have to resolve it by sending:

[aNetService resolve];

This will return immediately. For the return value you have to implement...

- (void)netServiceDidResolveAddress:(NSNetService *)sender;

...which will be called when the address has been resolved. Once you are there you can do this:

- (void)netServiceDidResolveAddress:(NSNetService *)sender
{
int firstOctet, secondOctet, thirdOctet, fourthOctet;
NSData *address = nil;
struct sockaddr_in *socketAddress;
NSString *ipAddressString = nil;
int port;

address = [[sender addresses] objectAtIndex:0];
socketAddress = (struct sockaddr_in *)[address bytes];
firstOctet = (socketAddress->sin_addr.s_addr & 0xFF000000) >> 24;
secondOctet = (socketAddress->sin_addr.s_addr & 0x00FF0000) >> 16;
thirdOctet = (socketAddress->sin_addr.s_addr & 0x0000FF00) >> 8;
fourthOctet = (socketAddress->sin_addr.s_addr & 0x000000FF) >> 0;
ipAddressString = [NSString stringWithFormat:@"%d.%d.%d.%d",
firstOctet, secondOctet, thirdOctet, fourthOctet];
port = socketAddress->sin_port;
...
}

I learned about this from the examples at:
<http://www.macdevcenter.com/pub/a/mac/2002/11/08/cocoa.html>

Bye, Wolfgang :-)


--
ARTIS Team Task -- Organize yourself and your team! It is a real timesaver.
Download now from: <http://www.artissoftware.com/teamtask>
_______________________________________________
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.
References: 
 >NSNetServiceBrowser (From: Lloyd Dupont <email@hidden>)

  • Prev by Date: NSDateFormatter specfier for "short date"
  • Next by Date: Re: Making my own NSScrollers
  • Previous by thread: Re: NSNetServiceBrowser
  • Next by thread: NSTableView and validateMenuItem:
  • Index(es):
    • Date
    • Thread