objectiveccoder001
objectiveccoder001

Reputation: 3031

Creating a socket client in Objective-C - Mac OSX

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?

Upvotes: 3

Views: 8774

Answers (2)

user557219
user557219

Reputation:

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).

Upvotes: 2

Chris Parker
Chris Parker

Reputation: 1252

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.

Upvotes: 5

Related Questions