Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa and TCP?

Cocoa and TCP?
Thread Tools
Fresh-Faced Recruit
Join Date: Nov 2001
Location: Charlotte, NC
Status: Offline
Reply With Quote
Nov 9, 2001, 11:26 AM
 
Does the Foundation or AppKit include classes for TCP/IP communication, or would this be something someone would be interested in? If it doesn't include them, I'll probably end up writing a framework that implements it.
     
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Nov 9, 2001, 12:06 PM
 
(Last edited by AirSluf; Nov 8, 2004 at 11:49 PM. )
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Nov 9, 2001, 01:04 PM
 
There is something in CoreFoundation called CFSocket, but there is very little documentation on it and it conforms to the methaphors of CF not of Obj-C/Cocoa. There is an Obj-C wrapper for BSD sockets called SmallSockets and is available at http://smallsockets.sourceforge.net/
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Nov 9, 2001, 10:04 PM
 
There isn't too much in the way of (public) networking classes in Cocoa unfortunately. NSURL can retrieve the contents for file:// or http[s]:// URLs, and NSFileHandle can be initialized with a TCP socket's file descriptor, meaning you can use NSFileHandle methods to read/write/be notified etc. The Message framework has one header which provides an easy API for sending email (i.e. SMTP). Past that there's not much in the kits.

If you're writing Java/Cocoa you obviously have all the Java networking APIs available. Even if you're primarily in Objective-C, there's nothing stopping you from writing one particular piece in Java so you can use Java networking, and messaging that one piece from ObjC across the bridge.

There are several third-party packages out there, as mentioned. The Omni frameworks are involved but offer a lot of stuff, whereas smallsockets (probably; I've never used it) gives you a lightweight API to TCP sockets.
EDInternet is probably somewhere in the middle, offering a handful of classes for different socket types that can be used as a basis for implementing higher level protocols (I think the author used them as part of an NNTP implementation). There is also
CURLHandle, which (according to its documentation) is a wrapper around libcurl in the form of an NSURLHandle subclass that can handle lots more types of URLs and provides for things like fetching in a background thread.
     
Grizzled Veteran
Join Date: Apr 2001
Status: Offline
Reply With Quote
Nov 9, 2001, 10:28 PM
 
There's a implementation out there called SmallSockets - it's a Obj-C implementation of sockets.

Keep in mind that you can also just use C code to call the BSD sockets API.

Wade
     
Dedicated MacNNer
Join Date: Sep 2000
Location: Brisbane, Queensland, Australia
Status: Offline
Reply With Quote
Nov 12, 2001, 04:03 AM
 
Personally I find using the C code just as easy for simple things. But there is absolutely no documentation on CFSocket I can find anywhere! No examples either!
     
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status: Offline
Reply With Quote
Nov 17, 2001, 03:19 PM
 
Originally posted by sordid:
<STRONG>Personally I find using the C code just as easy for simple things. But there is absolutely no documentation on CFSocket I can find anywhere! No examples either!</STRONG>
Read the header file CFSocket.h, it's pretty well documented. CFSocket is just a CF-wrapper around BSD sockets.
I usually just create a regular socket and use CFSocketCreateWithNative to convert it into a CFSocket for inserting into the current CFRunLoop (for getting a callback when new data arrives).

I've written an article that covers it roughly (including a CFSocket example!) which is available at cocoadevcentral.
     
Dedicated MacNNer
Join Date: Sep 2000
Location: Brisbane, Queensland, Australia
Status: Offline
Reply With Quote
Nov 19, 2001, 04:56 AM
 
Originally posted by amonitzer:
<STRONG>

Read the header file CFSocket.h, it's pretty well documented. CFSocket is just a CF-wrapper around BSD sockets.
I usually just create a regular socket and use CFSocketCreateWithNative to convert it into a CFSocket for inserting into the current CFRunLoop (for getting a callback when new data arrives).

I've written an article that covers it roughly (including a CFSocket example!) which is available at cocoadevcentral.</STRONG>
Thanks for the tips.. they have been very helpful.

     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:50 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2