objective c - iOS - How do I create a read and write stream to a network socket? -
i new ios development. attempting create read , write stream. using cfnetworking programming guide's examples try , working.
i trying schedule read stream on run loop work around issue of streams blocking. right away have run issues. how can create cfhost object using cfhhostcreatewithaddress? here have far:
nsstring *address = @"irc.ubuntu.net"; cfdataref addressdataref = (cfdataref)[address datausingencoding:nsasciistringencoding]; cfhostref host = cfhostcreatewithaddress(kcfallocatordefault, addressdataref); //create read , write stream cfstreamcreatepairwithsockettocfhost(kcfallocatordefault, host, 8008, &readstream, &writestream);
the second line bombs. can please tell me how create cfhostref?
thanks lot!
the documentation states second argument cfhostcreatewithaddress() must "a cfdataref object containing sockaddr structure address of host. value must not null."
you're passing cfdataref representing "irc.ubuntu.net", no means sockaddr struct.
use cfhostcreatewithname:
cfhostref cfhostcreatewithname ( cfallocatorref allocator, cfstringref hostname );
as know, can cast nsstring * cfstringref, or create constant cfstringref macro cfstr().
Comments
Post a Comment