FROM : Daniel Smith
DATE : Fri Jan 18 23:17:58 2008
On Jan 18, 2008, at 2:01 PM, Hamish Allan wrote:
> On Jan 18, 2008 7:07 PM, Daniel Smith <<email_removed>> wrote:
>
>> Any suggestions? Can I make this code work? Or should I be trying a
>> different approach (note that I don't want to change the server in
>> any way)? Perhaps I'd be better off using lower-level APIs?
>
> Take a look at http://developer.apple.com/documentation/Cocoa/
> Conceptual/Streams/Articles/NetworkStreams.html
>
> Hamish
Thanks for that suggestion. I had looked into
NSStream:getStreamsToHost previously, and forgot to mention why I
avoided it: I'm using Bonjour to locate the server, which gives me an
NSNetService. The address information I get from
NSNetService:addresses is already encoded as a sockaddr struct.
While my example didn't demonstrate it, what I was ultimately trying
to use is the NSSocketPort:initRemoteWithProtocolFamily:...
constructor, because it takes a sockaddr as input. Alternatively, I
would need to be able to map from the sockaddr to an IP address and
port in a format that NSStream:getStreamsToHost or some other method
understands.
I'm not wild about the idea of turning an IP address encoded as bytes
into a string, just so that I can conform to an interface (which will
promptly parse my string into bytes again); and while NSNetService
has a hostName method, I don't like the idea of generating another
DNS query just to resolve a host name that has already been resolved,
either.
—Dan
DATE : Fri Jan 18 23:17:58 2008
On Jan 18, 2008, at 2:01 PM, Hamish Allan wrote:
> On Jan 18, 2008 7:07 PM, Daniel Smith <<email_removed>> wrote:
>
>> Any suggestions? Can I make this code work? Or should I be trying a
>> different approach (note that I don't want to change the server in
>> any way)? Perhaps I'd be better off using lower-level APIs?
>
> Take a look at http://developer.apple.com/documentation/Cocoa/
> Conceptual/Streams/Articles/NetworkStreams.html
>
> Hamish
Thanks for that suggestion. I had looked into
NSStream:getStreamsToHost previously, and forgot to mention why I
avoided it: I'm using Bonjour to locate the server, which gives me an
NSNetService. The address information I get from
NSNetService:addresses is already encoded as a sockaddr struct.
While my example didn't demonstrate it, what I was ultimately trying
to use is the NSSocketPort:initRemoteWithProtocolFamily:...
constructor, because it takes a sockaddr as input. Alternatively, I
would need to be able to map from the sockaddr to an IP address and
port in a format that NSStream:getStreamsToHost or some other method
understands.
I'm not wild about the idea of turning an IP address encoded as bytes
into a string, just so that I can conform to an interface (which will
promptly parse my string into bytes again); and while NSNetService
has a hostName method, I don't like the idea of generating another
DNS query just to resolve a host name that has already been resolved,
either.
—Dan
| Related mails | Author | Date |
|---|---|---|
| Daniel Smith | Jan 18, 20:07 | |
| Hamish Allan | Jan 18, 21:01 | |
| Daniel Smith | Jan 18, 23:17 | |
| Chris Parker | Jan 18, 23:30 | |
| Daniel Smith | Jan 19, 00:15 |






Cocoa mail archive

