FROM : Chris Hanson
DATE : Sat Jan 18 22:03:30 2003
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_removed>
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: <email_removed>
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Sat Jan 18 22:03:30 2003
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_removed>
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: <email_removed>
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| Mickael BALAN | Jan 18, 20:17 | |
| Chris Hanson | Jan 18, 22:03 |






Cocoa mail archive

