Skip navigation.
 
mlRe: Reading a string from a socket
FROM : Daniel Smith
DATE : Sat Jan 19 00:15:28 2008

On Jan 18, 2008, at 4:30 PM, Chris Parker wrote:

>
> On Jan 18, 2008, at 2:17 PM, Daniel Smith wrote:
>

>> 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.

>
> If you're using NSNetServices to discover hosts, can't you just use 
> this method:
>
>     - (BOOL)getInputStream:(NSInputStream **)inputStream outputStream:
> (NSOutputStream **)outputStream;
>
> defined in NSNetServices.h to pick up the streams? This completely 
> forgoes any resolution and just fills in the streams parameters for 
> you.
>
> .chris
>
> --
> Chris Parker
> Cocoa Frameworks
> Apple Inc.


I must have tried that, too, but it was awhile ago and I don't recall 
what happened.  I'll investigate and let you know.

—Dan

Related mailsAuthorDate
mlRe: Reading a string from a socket Daniel Smith Jan 18, 20:07
mlRe: Reading a string from a socket Hamish Allan Jan 18, 21:01
mlRe: Reading a string from a socket Daniel Smith Jan 18, 23:17
mlRe: Reading a string from a socket Chris Parker Jan 18, 23:30
mlRe: Reading a string from a socket Daniel Smith Jan 19, 00:15