我如何在 xcode 中打开一个套接字?Mac OSX

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6990047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:41:31  来源:igfitidea点击:

How do i open a socket in xcode? Mac OSX

objective-cxcodemacos

提问by Tyler McMaster

I need to open a socket; for example, on port 190. How would I do this in Objective-C?

我需要打开一个套接字;例如,在端口 190 上。我将如何在 Objective-C 中执行此操作?

P.S: This would be for reading and writing.

PS:这将用于阅读和写作。

回答by nycynik

this may help you, has code:

这可能对你有帮助,有代码:

https://discussions.apple.com/message/7815634?messageID=7815634#7815634?messageID=7815634

https://discussions.apple.com/message/7815634?messageID=7815634#7815634?messageID=7815634

The key search term is going to be "open socket".

关键搜索词将是“打开套接字”。

回答by vilhalmer

If you'd like to have something that handles the lower-level stuff for you, check out AsyncSocket. It is completely asynchronous, handles errors and status changes, and uses the delegate pattern to let you know when stuff happens.

如果您想为您处理较低级别的内容,请查看 AsyncSocket。它是完全异步的,处理错误和状态变化,并使用委托模式让你知道什么时候发生了事情。

https://github.com/robbiehanson/CocoaAsyncSocket

https://github.com/robbiehanson/CocoaAsyncSocket

(I'd still recommend that you learn the basics of how sockets work, so writing it yourself first might not be a bad idea.)

(我仍然建议您学习套接字工作原理的基础知识,所以先自己编写它可能不是一个坏主意。)