Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!uwvax!dogie!uwmcsd1!ig!agate!ucbvax!ucsfcgl!cgl.ucsf.edu!mday
From: mday@cgl.ucsf.edu
Newsgroups: comp.windows.news
Subject: Client/Server communications
Keywords: cid utilities, NeWS programming
Message-ID: <11010@cgl.ucsf.EDU>
Date: 20 Jun 88 22:36:11 GMT
Sender: daemon@cgl.ucsf.edu
Reply-To: mday@cgl.ucsf.edu
Organization: UCSF Computer Graphics Lab
Lines: 81

I'm having some problems communicating between the NeWS server and client.
Perhaps a more enlightened NeWS programmer can point out the error in my ways.

The first problems I am having, is coming up with an acceptable method of
sending a larger number of lineto's from a client, in response to an event
posted by the server. I have tried several approaches, with no success.

Plan A)  Normally in a C program, I would pass the data array by address. 
	 Of course this won't work under NeWS because the client and server
	 don't share address space.

Plan B)  Use the cid utilities to synchronize communication between the client
	 and the server.  In response to a repaint event at the server,
	 invoke a procedure that sets up the correct graphics context.
	 Then for each vector to be drawn, perform
		 lineto_ps (id, x, y)

	where lineto_ps is defined to be:
	cdef lineto_ps (int id, float x, float y)
		id { x y lineto } sendcidevent

	The problem with this approach is it is painfully slow.  The NeWS
	Application Scenario admits that the cid utilities have too much
	overhead to be used when sending lots of vectors.  Unfortunately, the
	manual doesn't spell out a more efficient alternative.

Plan C) Only use the cid utilities to set up the correct graphics context.
	After the context is set up, invoke a PostScript routine on the
	server that performs a lineto without using sendcidevent.  Since, 
	cid utilities are only used to begin and terminate each event, this 
	shouldn't exhibit the poor performance of Plan B.
	Unfortunately, my implementation of this doesn't seem to work.
	It seems that there is an implicit save and restore of the graphics
	context bracketing each sendcidevent, so that the lineto procedure
	isn't being sent to the correct canvas, or perhaps is being ignored
	completely.

The second problem I am having is closely related to the above.  I would like
to send a variable number of character strings to the NeWS server in response
to a user generated event. I haven't found any way of invoking a cdef routine
with a variable number of arguments, so a reasonable thing to do is put all
of the strings into an array on the stack. As an example my PostScript code
for a repaint event is:

	/PaintClient {
		DAMAGE_TAG tagprint
		uniquecid dup typedprint
		[exch cidinterest] forkeventmgr
		waitprocess pop
		show_strings
		} def

	cdef repaired (int id)
		id { exit } sendcidevent

the show_strings procedure simply prints the passed strings into a window.

The server side code looks like:
	if (get_damage(&id))  {
		while (fgets(buff, sizeof(buff), fptr))
			psio_fprintf(PostScript, "%s\n", buff);
		repaired(id);
          }

This approach fails, because after the waitprocess exits, there isn't
anything on the stack.  I assumed that by using psio_fprintf, all of the
characters I sent would end on the stack of the server.  This is obviously
not happening.  Does using waitprocess preclude the use of the psio routines?

Does anybody have any pointers?  Should I abandon the use of the cid utilities?
The NeWS manuals suggest that synchronization between client and server is
a good thing, but either I am not using these utilities correctly, or they
are more trouble than they are worth.

Thanks in advance,
Mark
----------
		Mark Day
UUCP:		..ucbvax!ucsfcgl!mday
ARPA:		mday@cgl.ucsf.edu
BITNET:		mday@ucsfcgl.BITNET