Re: Get IP address and info from FileHandle
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.