Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[MacOS X] Socket programming with Objective-C

193 views
Skip to first unread message

Benjamin [bklein] Klein-Fignier

unread,
Oct 24, 2001, 8:21:06 PM10/24/01
to
Hi !

I'm looking for informations about socket programming with Objective-C
and MacOS X. I know I can use system calls like accept, liste, socket,
bind,... but I would like to use the MacOS Object Framework.

On ADC, I found some classes which looks like networking ones (like
NSSocketPort in the Foundation Kit), but documentations are pretty
*empty* :(

So, does someone know how to use Foundation Kit / Objective-C to do
socket programming ?

Best regards,

--
Benjamin "bklein" Klein-Fignier <bkl...@4ben.net>
Black holes are where God divided by zero.

Kevin Reid

unread,
Oct 25, 2001, 8:47:18 AM10/25/01
to
Benjamin [bklein] Klein-Fignier <bkl...@4ben.net> wrote:

> I'm looking for informations about socket programming with Objective-C
> and MacOS X. I know I can use system calls like accept, liste, socket,
> bind,... but I would like to use the MacOS Object Framework.
>
> On ADC, I found some classes which looks like networking ones (like
> NSSocketPort in the Foundation Kit), but documentations are pretty
> *empty* :(

I think NSFileHandle is the appropriate class, though it doesn't wrap
socket(), etc.

I haven't yet used it in my own program, but it appears that
NSFileHandle is a wrapper around a file descriptor to allow reading
without blocking or polling; the documentation seems clear on how to use
it with a socket.

I don't know what NSSocketPort is for.

--
Kevin Reid

Benjamin [bklein] Klein-Fignier

unread,
Oct 25, 2001, 9:35:44 AM10/25/01
to
On Thu, 25 Oct 2001 at 12:47 GMT, Kevin Reid <kpr...@attglobal.net> wrote:
> I think NSFileHandle is the appropriate class, though it doesn't wrap
> socket(), etc.
>
> I haven't yet used it in my own program, but it appears that
> NSFileHandle is a wrapper around a file descriptor to allow reading
> without blocking or polling; the documentation seems clear on how to use
> it with a socket.

Thanks ! It seems to be the right class for socket programming.

> I don't know what NSSocketPort is for.

I wonder what it is for...

Johann Hibschman

unread,
Oct 25, 2001, 1:55:35 PM10/25/01
to
>>>>> "Benjamin" == Benjamin [bklein] Klein-Fignier <Benjamin> writes:

>> I haven't yet used it in my own program, but it appears that
>> NSFileHandle is a wrapper around a file descriptor to allow
>> reading without blocking or polling; the documentation seems
>> clear on how to use it with a socket.

Benjamin> Thanks ! It seems to be the right class for socket
Benjamin> programming.

You might also want to look at

http://smallsockets.sourceforge.net/

I haven't tried it myself, but its precis is:

The purpose of this library is to provide an extremely lightweight
Objective-C Cocoa interface to BSD sockets.

Other such libraries exist, such as The Omni Group's excellent
OmniNetworking framework. However, OmniNetworking may be more overhead
than you want if you are not using the remainder of the Omni
Frameworks.

The goal of SmallSockets is to provide a complete and robust sockets
wrapper in as few files as practical, with no dependencies on anything
other than what comes on the Mac OS X Developer CD.

Full source code, as well as sample applications, is included.

I hope that helps.

--J

David Phillip Oster

unread,
Oct 25, 2001, 2:36:04 PM10/25/01
to
In article <slrn9temn5...@meiji.in.4ben.net>, "Benjamin
[bklein] Klein-Fignier" <bkl...@4ben.net> wrote:

> I'm looking for informations about socket programming with Objective-C
> and MacOS X. I know I can use system calls like accept, liste, socket,
> bind,... but I would like to use the MacOS Object Framework.


You might also want to look in to OpenPlay, the cross-platform
lightweight networking classes.

John C. Randolph

unread,
Oct 25, 2001, 8:19:51 PM10/25/01
to
"Benjamin [bklein] Klein-Fignier" wrote:
>
> On Thu, 25 Oct 2001 at 12:47 GMT, Kevin Reid <kpr...@attglobal.net> wrote:
> > I think NSFileHandle is the appropriate class, though it doesn't wrap
> > socket(), etc.
> >
> > I haven't yet used it in my own program, but it appears that
> > NSFileHandle is a wrapper around a file descriptor to allow reading
> > without blocking or polling; the documentation seems clear on how to use
> > it with a socket.
>
> Thanks ! It seems to be the right class for socket programming.
>
> > I don't know what NSSocketPort is for.
>
> I wonder what it is for...

According to the docs:

NSSocketPort is a subclass of NSPort which can be used as an endpoint
for Distributed Object connections (or raw messaging). A companion
class, NSMessagePort allows for local (on the same machine)
communication only. NSSocketPort, allows for both local and remote
communication, but may be more expensive than NSMessagePort for the
local case; there is also no name registry service for NSSocketPorts --
clients and servers must agree on the TCP port numbers to use beforehand.

-jcr

0 new messages