问题
I need to basically send some "data" to 98.136.86.109 at port 587. How can I do this in obj-c in my mac app?
回答1:
As Yan notes in his answer, you could use the standard BSD-style networking APIs like socket(), connect(), etc. However, if you want to stay in Objective C and Foundation, then you're looking for NSInputStream and NSOutputStream, which are the stream classes for Cocoa. You should not, however, look at NSSocketPort as that's specifically for use with Distributed Objects.
Apple's "Introduction to Stream Programming Guide for Cocoa" is here: http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Streams/Streams.html
You should start with that document and then check out the class references which have pointers to sample code projects which use NSStream and its subclasses.
回答2:
If you don’t mind using third-party code, AsyncSocket is a popular library that wraps CFSocket and CFStream, providing an Objective-C API for communication via TCP and UDP (AsyncUdpSocket).
来源:https://stackoverflow.com/questions/6240696/creating-a-socket-client-in-objective-c-mac-osx