What is the iOS equivalent to Android Socket programming code?

孤街醉人 提交于 2019-12-13 11:26:48

问题


I have some socket programming code in Android (Java) and I want to implement the same thing in iOS (Objective-C).

On iOS, NSStream, NSInputStream, NSOutputStream are some of the classes for socket programming.

I have doubts when comparing them to some methods on Android's SocketChannel class.

socketChannel.configureBlocking
socketChannel.setSoTimeout
socketChannel.connect 
socketChannel.finishConnect
socketChannel.isConnected

What are the equivalent methods in iOS classes like NSStream, NSInputStream?

And also ByteBuffer on Android has a position() method. What is the equivalent method in iOS?

I know the NSStream constants are there, but I am confused about how they map to Android code. Could you please suggest which methods are equivalent in iOS?


回答1:


You don't translate code line by line. Different platforms and even different frameworks use different styles of API.

Since your question doesn't say what you are trying to do, I can only recommend that you read more about how stream and socket programming works on iOS in

  • the Stream Programming Guide, or
  • the CFNetwork Programming Guide (if you want to read more about lower level (Core Foundation) networking code on iOS), or
  • the Networking Overview (if you want to read more about networking code in general on iOS)


来源:https://stackoverflow.com/questions/27404321/what-is-the-ios-equivalent-to-android-socket-programming-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!