• 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: Get IP address and info from FileHandle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get IP address and info from FileHandle


  • Subject: Re: Get IP address and info from FileHandle
  • From: Chris Hanson <email@hidden>
  • Date: Sat, 18 Jan 2003 15:03:30 -0600

At 8:17 PM +0100 1/18/03, Mickael BALAN wrote:
I create a network server which receive connection asynchonous using FileHandle.
Now I want to get informations (IP address, port, ...) of peer clients.
Is anyone have solution to do that in cocoa ?

Are you trying to find the information of the client connecting to you? Or are you trying to find peers on your network that are providing (and advertising) some service?

The former you can do by interrogating the client-connection file handle that's included in each connection-accepted notification. Send it -fileDescriptor to get its underlying file descriptor (socket) and then use getsockname() to get the sockaddr_in for that socket:

struct sockaddr_in address;
int addressSize = sizeof(address);
int fd = [acceptedFileHandle fileDescriptor];

if (getsockname(fd, (struct sockaddr *)&address, &addressSize) == -1) {
// raise an exception here on failure
}
// at this point address contains the IP address and port
// of the remote client

The latter you can do using NSNetServiceBrowser, assuming your peers are advertising the service they provide via Rendezvous (multicast DNS). It's pretty easy; look at the PictureSharing and PictureSharingBrowser examples in /Developer/Examples/Foundation.

-- Chris

--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
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: 
 >Get IP address and info from FileHandle (From: Mickael BALAN <email@hidden>)

  • Prev by Date: NSNetService gotcha
  • Next by Date: Re: Re(2): NSTextField selectText behaviour (Currency Converter Tut)
  • Previous by thread: Get IP address and info from FileHandle
  • Next by thread: NSNetService gotcha
  • Index(es):
    • Date
    • Thread