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

Re: MACTCP for a server?



Hi Shen-

	Yes, you can build a server on top of the standard library.  The 
problem is that the calls to MacTCP are blocking, and you want to do 
other things while you wait for a connection.  The thing to do is to put 
a function in the *eventhook* that periodically opens passively on your 
main port, with a commandtimeout of 1 (unfortuately, you can't make it 
shorter.. ): 

	You must use the handler-case macro to catch the MacTCP error that 
occurs with a MacTCP timeout, calling your switching function (to tell 
the client to open on another port and to wait for a connection).  In my 
code, I actually check for incoming commands and connections in my 
*eventhook* function, as well as doing everything else there.  You may 
be able to get away with one main loop that does whatever for all 
connected clients and then use the event stuff to only add new clients, 
but I haven't tried it.

	The TCP-eval-server code from the ftp site is instructive; check it 
out, although instead of ccl::%add-periodic-task, put your function in 
the *eventhook*.  It's much harder to stop it if it runs away with an 
error or hangs in the periodic task list.

	Well, hope that helps...

Bruce Krysiak
brucek@mit.edu
MIT Media Lab
Epistemology and Learning Group