Thread View: comp.sys.next.programmer
3 messages
3 total messages
Started by Dwight Everhart
Thu, 31 Dec 1992 04:41
Sending objects between processes
Author: Dwight Everhart
Date: Thu, 31 Dec 1992 04:41
Date: Thu, 31 Dec 1992 04:41
38 lines
2614 bytes
2614 bytes
I'm writing a software system involving a server process and several client processes. I'm writing them in Objective-C, although the server is a daemon, not an application (it doesn't have a NXApp). The clients may or may not be applications. I'm using Speaker and Listener objects for the RPC requests. I need to be able to send objects between the clients and the server. I first tried sending them as a char blocks in the Speaker/Listener messages. That worked fairly well, but I ran into problems when the class of the object sent was not linked into the server. (I'm dynamically loading classes as they're needed.) I was also confused about whether the memory was being copied and who was responsible for freeing it. My second (and latest) approach is to use typed streams on ports, and send the objects using NXWriteObject() and NXReadObject(). However, I'm having a problem opening the typed streams for reading. When I call NXOpenTypedStream(), it hangs, apparently blocking on the stream. I assumed it was trying to read some header information identifying the type or version of the stream, so I had the client send an object before the server tried to open the stream. Same thing happened. What am I doing wrong? I'm having the client create the port and give the server receive rights through a Speaker/Listener message. The client creates the stream and typed stream on its end for writing, and the server takes the port given and creates a stream and typed stream for reading. I don't want to send any objects at this point in the code. I just want to establish ports and streams for sending and receiving objects later. Does NXOpenTypedStream() try to read the stream, and, if so, why didn't it read the object the client sent? If you know of a better way to send objects between processes, please explain. I'm running 2.0, so I don't have distributed objects. Do they offer a better approach? -- Dwight Everhart "You can't do a musical number about elephants Houston, Texas without it being obvious." -- Roger Ebert biff@biff.gbdata.com NeXTMail and MIME OK
Re: Sending objects between processes
Author: Dwight Everhart
Date: Thu, 31 Dec 1992 07:27
Date: Thu, 31 Dec 1992 07:27
28 lines
1994 bytes
1994 bytes
In article <C03x19.Jx2@biff.gbdata.com> I write: >My second (and latest) approach is to use typed streams on ports, and >send the objects using NXWriteObject() and NXReadObject(). However, >I'm having a problem opening the typed streams for reading. When I call >NXOpenTypedStream(), it hangs, apparently blocking on the stream. I >assumed it was trying to read some header information identifying the >type or version of the stream, so I had the client send an object before >the server tried to open the stream. Same thing happened. I figured out what was happening here. NXOpenTypedStream() is trying to read something from the stream. The reason it hung even when the client wrote an object before the server opened the stream was because the client didn't flush the stream after writing the object. In fact, it's not necessary to write an object. What is important is calling NXFlushTypedStream() after opening a typed stream for writing. In most cases, NXFlushTypedStream() is also needed after a write to a typed stream on a port. I'm still interested in suggestions for alternative ways of sending objects between processes. I don't think I can use the pasteboard because security is important in my system. I have to be sure that objects are read only by the intended processes and that objects are written only by authorized processes. -- Dwight Everhart "You'd be surprised what you can get used to Houston, Texas when your only other choice is Houston" biff@biff.gbdata.com -- Chagall Guevara NeXTMail and MIME OK
Re: Sending objects between processes (SUMMARY)
Author: Dwight Everhart
Date: Tue, 05 Jan 1993 06:29
Date: Tue, 05 Jan 1993 06:29
98 lines
5725 bytes
5725 bytes
In article <C03x19.Jx2@biff.gbdata.com> I wrote: > I'm writing a software system involving a server process and several client > processes. I'm writing them in Objective-C, although the server is a > daemon, not an application (it doesn't have a NXApp). The clients may or > may not be applications. I'm using Speaker and Listener objects for the > RPC requests. > > I need to be able to send objects between the clients and the server. [Description of first approach deleted.] > My second (and latest) approach is to use typed streams on ports, and send > the objects using NXWriteObject() and NXReadObject(). I ended up using a typed stream on a memory buffer, and then sending the buffer to the other process through a block in a Speaker/Listener message. I switched to buffers because of an interesting problem I had with ports. I was keeping the typed stream open and sending several objects through it. However, when the stream was read, only the first object was returned, no matter how many times it was read or how many objects were written to it. Apparently only one object can be sent over one typed stream. The solution was to open a typed stream for each object. Since I wanted to minimize the amount of code I had to write, I switched to buffers. NeXT already provides a function, NXWriteRootObjectToBuffer(), that allocates the buffer, opens the typed stream on it, writes the object, truncates the buffer, and closes the stream -- all in one function! There isn't an equivalent function for ports. The system seems to be working now, although I am not sure who should be freeing the memory buffer sent through the Speaker/Listener message. The manual says that NXFreeObjectBuffer() should be called to free the buffer when it is not needed anymore. However, the same manual says that blocks sent in Speaker/Listener messages are automagically freed. So who frees memory buffers created by NXWriteRootObjectToBuffer() and sent through a Speaker/Listener message? As I said in my previous article, I'm not using distributed objects because I'm running 2.0. I'm hesitant about upgrading to 3.0 because of it's performance impact (I have an '030 cube) and its bugs. > If you know of a better way to send objects between processes, please > explain. I'm running 2.0, so I don't have distributed objects. Do they > offer a better approach? Three people replied, and they all suggested distributed objects. Montgomery Zukowski <monty@intuitiveedge.com> writes: > I think that sending objects over typed streams will work fine as > long as you also send the class to be dynamically loaded, probably easiest > to send the filename of the modules to link in, although for security you > might want to send the object data itself. > Even distributed objects in 3.0 requires that the classes of > objects be loaded in the recieving progrtamm so that copies can be > instantiated when they are recieved. Distributed Objects does have a > transport protocol which specifies how to encode and decode objects which > are passed between programs, you might want to look at it for ideas. It is > needed because some objects passes may be distributed objects while others > are going to be copied and instantiated. If you don't need to maintain > connections accross programs, then you don't really need distributed > objects. From your description you seem to only need to pass objects and > not maintain a connection to the server's objects. Timothy J. Wood <bungi@u.washington.edu> writes: > Yes! They handle everything for you (except making sure the class in > linked in). For example, say I have two processes, A and B. A has a list, > and B has some items that it wishes to put in A's list. A would simply > 'vend' the object (two lines of code). B would look up the vended object > (one line of code which returns an id). B could then treat that id exactly > like it was the real object since all messages to it would be bundled up > and transmitted to the real object. When B sends it's object id's to the > proxy for A's list, it could specify to send a copy, rather than the whole > object. > I would strongly suggest that you take a look at Distributed Objects. > They are by far the coolest thing that NeXT has done in version 3.0. Paul Burchard <burchard@localhost.gw.umn.edu> writes: > Distributed Objects is the best way to do all this stuff, even with > the extra twist of dynamic loading. You can do what you want, with > fine control over freeing responsibilities and good transparency to > the rest of the code, using the NXTransport protocol (one of the > highlights of D.O.). Check it out and ask me if you need more > info... Thanks to all who responded. Although distributed objects sound good, I'll use typed streams for now, since I have them working, and I don't have 3.0. -- Dwight Everhart "Spring will come for IBM when people Houston, Texas start buying big computers again." biff@biff.gbdata.com -- John Akers, CEO of IBM NeXTMail and MIME OK
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads