Re: Reading a string from a socket
Re: Reading a string from a socket
- Subject: Re: Reading a string from a socket
- From: Daniel Smith <email@hidden>
- Date: Fri, 18 Jan 2008 16:17:58 -0600
On Jan 18, 2008, at 2:01 PM, Hamish Allan wrote:
On Jan 18, 2008 7:07 PM, Daniel Smith <email@hidden> 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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden