Re: New to cocoa; okay to use C sockets?
Re: New to cocoa; okay to use C sockets?
- Subject: Re: New to cocoa; okay to use C sockets?
- From: Douglas Davidson <email@hidden>
- Date: Thu, 5 Jul 2001 13:09:26 -0700
On Thursday, July 5, 2001, at 08:54 AM, Navdeep Gill wrote:
I am workin on doing some TCP/IP programmin in
Cocoa. I was wondering if there are any special
objects in C that I can use for socket programming or
should I just go ahead and use the common 'socket(),
bind(), listen() and accept()' calls?
It is absolutely okay to just go ahead and use the standard BSD sockets
calls that you are used to. However, there are also some other things
that you may wish to use from within Cocoa. For example, if you are
writing a Cocoa application, and you want to listen on a socket, and you
don't want to spawn an additional thread to handle it, you can use
CFSocket (in CoreFoundation) to get callbacks on your main thread,
within the standard event loop, when data is available. If you want
object-oriented wrappers around TCP/IP sockets, there are some
third-party frameworks you might want to look at, notably OmniNetworking.
At a somewhat higher level, if you are communicating between two Cocoa
processes, and you just want IPC between them without too much concern
for the details of the mechanism, you can use NSPort to do so--there are
subclasses of NSPort for local and for networked communication. At an
even higher level, if you want to send Objective-C messages from one
application to another, you can use Distributed Objects.
Depending on the protocol you want to use, there are also various other
objects that may be able to help you, e.g. NSURL or CFURL for http.
Douglas Davidson