How to transmit user-defined object between client and server?

goran.krampe at bluefish.se goran.krampe at bluefish.se
Thu Jun 3 08:08:27 UTC 2004


Hi Kwiyi!

kwiyi woo <kwiyiwoo at yahoo.com> wrote:
> Hello,
> I need to create a client and server application. I need to exchange information between client and server. I know I can use socketstream to transmit string between clent and server. 
> But I need to exchange info which is not a string, but an user-defined object. I cannot find corresponding class in Squeak 3.6. The only thing I find might be helpful is class ArbitraryObjectSocket. But when I tried to initialize it by 
> arbisocket := ArbitraryObjectSocket on: aSocket. 
> it threw error message. 

ArbitraryObjectSocket should be usable - but it might have suffered
"bit-rot", I don't know.

What you want to do is to serialize (= turn into a byte sequence that
can be used later to reassemble the object) an object, send it over, and
then de-serialize it on the other side. You can of course do this
manually using typically ReferenceStream. A very compact example first
serializing and then de-serializing an array with two elements:

(ReferenceStream on:
	(ByteArray streamContents: [:stream |
		(ReferenceStream on: stream)
			nextPut: #('hi' 4711)])
		readStream) next

...you can play by selecting parts of the above expression and inspect
it. Like inspecting this part to see the resulting byte array:

ByteArray streamContents: [:stream |
		(ReferenceStream on: stream)
			nextPut: #('hi' 4711)]
 

regards, Göran

PS. You might want to avoid posting with HTML to the list, people tend
to not like that! Not sure if yahoo allows you to turn it off of course.
:) :)



More information about the Squeak-dev mailing list