discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSRunLoop questions


From: Richard Frith-Macdonald
Subject: Re: NSRunLoop questions
Date: Mon, 17 Dec 2001 07:33:35 +0000

On Monday, December 17, 2001, at 12:31 AM, Jay McCarthy wrote:

Hello,

This weekend I was looking into what the best way to write an internet
server using GNUstep was. I noted that there was no native support in
GNUstep for socket abstractions or anything of that nature. I also noted
that you could use NSFileHandle as a wrapper around a socket to use it
in a GNUstep application.

That would be great for the client side of something but it doesnt
necessarily work for a server which would need to handle multiple
clients. Then I looked into NSRunLoop and figured that it would be the
best way to do, because it was made to monitor input sources for data.

Actually, it works fine for servers-
See +fileHandleAsServerAtAddress:service:protocol:
and -acceptConnectionInBackgroundAndNotifyForModes:

After looking into this I tried to write an class that I could use, but
I ran into a problem about the proper way a port should respond to an
NSRunLoop. There was no obvious example of something that could be used
in an NSRunLoop either - other than a timer. The problem I hit was that
any time I used -addPort: port toMode: mode I would get the error:
"Uncaught exception NSInvalidArgumentException, reason: RunLoop listener
has no event handling method"
Which comes from the port object not responding to the "eventSel"
method. A quick grep through the headers and source of Foundation and
AppKit doesnt return any classes that support this method.

the -addPort:forMode: method adds an NSPort object to a runloop ... this is
part of the distributed objects system and nothing to do with sockets.

My questiones are-
Is NSRunLoop usuable for what I want?

Easily via NSFileHandle - whaich has methods to do mit all for you.
In MacOS-X, you would use similar NSFileHandle stuff, but wouldn't
have the convenience methods to create the sockets for you.

A lower-level interface (more efficient, but more work to be done)
is provided by the GNUstep NSRunLoop 'event' extensions (documented
in the header file)

Should I subclass NSPort - or use NSPort - and how would I do such a
thing?

No.

Is there already some sort of Framework written to accomplish this?
How was this done with OPENSTEP - and does anyone know of an application
with an open source I could look at for inspiration and education?

In OPENSTEP you would use unix socket calls to create a socket, then
create and use an NSFileHandle with the descriptor of that socket.

In GNUstep, the preferred way to do it is the same, except that we have
a few additional NSFileHandle methods that stop you having to use unix-specific
socket code.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]