sockets - Using NSHost in iOS -
i'm trying make socket server application in swift ios. found great example:
let addr = "127.0.0.1" let port = 4000 var host :nshost = nshost(address: addr) var inp :nsinputstream? var out :nsoutputstream? nsstream.getstreamstohost(host, port: port, inputstream: &inp, outputstream: &out) let inputstream = inp! let outputstream = out! inputstream.open() outputstream.open() var readbyte :uint8 = 0 while inputstream.hasbytesavailable { inputstream.read(&readbyte, maxlength: 1) } // buffer uint8 array containing bytes of string "jonathan yaniv.". outputstream.write("hello", maxlength: "hello".length)
i tried run code in xcode , said nshost didn't exist. googled , found nshost wasn't able ios. can use instead?
edit
i'm using cocoa async socket socket connections. can find here cocoaasyncscket
change getstreamstohost getstreamstohostwithname
change:
nsstream.getstreamstohost(host, port: port, inputstream: &inp, outputstream: &out)
to
nsstream.getstreamstohostwithname(addr, port: port, inputstream: &inp, outputstream: &out)
Comments
Post a Comment