Remote method calls?
Lic. Edgar J. De Cleene
edgardec2001 at yahoo.com.ar
Sat Nov 20 15:07:55 UTC 2004
On 20/11/04 06:33, "William G. Davis" <william_gordon_davis at yahoo.com>
wrote:
> Hi everyone.
>
> I'm somewhat new to Squeak and to Smalltalk in
> general. I want to know what the preferred mechanism
> is for sending messages over a network to some remote
> object.
>
> Is there any special way of doing this? I looked in
> Network-ObjectSocket, but it's undocumented and
> doesn't seem functional.
>
> Any replies are appreciated.
Wiliam:
You have some large and informative answer.
So I add some begginers trick;
>From rST of Diego Gomez deck we have:
getObject
"gets a serialized object from this socket"
| encoded object |
encoded := String new writeStream.
[encoded size isZero]
whileTrue: [encoded nextPutAll: self getData].
[self isConnected
and: [self dataAvailable]]
whileTrue: [encoded nextPutAll: self getData].
object := ReferenceStream unStream: encoded contents.
^ object
And :
endObject: anObject
"sends a serialized object to this socket"
| encoded |
encoded := ReferenceStream streamedRepresentationOf: anObject.
self sendData: encoded
I have in Socket and use it in network games as:
sendMyData
| t1 t2 t3 t4 |
serverOrClient = #server
ifTrue: [activeSocket := socketList at: playerTurn].
(activeSocket isValid
and: [activeSocket isConnected])
ifTrue: [t1 := OrderedCollection new.
t1 add: self losJugadores.
t1 add: self cartasOrden.
t1 add: self ronda.
t1 add: self numCarta.
t1 add: self cambiosTotales.
t2 := Array new: 42.
1
to: 42
do: [:t5 |
t3 := self submorphs at: t5.
t4 := Array new: 2.
t4 at: 1 put: t3 ejercitos.
t4 at: 2 put: t3 deQuienSoy.
t2 at: t5 put: t4].
t1 add: t2.
t1 add: self playerTurn.
activeSocket sendObject: t1].
[activeSocket dataAvailable] whileFalse.
self askMyData
and:
askMyData
| t1 t2 t3 t4 t5 t6 |
t1 := activeSocket getObject.
self
losJugadores: (t1 at: 1).
self
cartasOrden: (t1 at: 2).
self
ronda: (t1 at: 3).
self
numCarta: (t1 at: 4).
self
cambiosTotales: (t1 at: 5).
t2 := t1 at: 6.
1
to: 42
do: [:t7 |
t3 := t2 at: t7.
t4 := self submorphs at: t7.
t4
ejercitos: (t3 at: 1).
t4
deQuienSoy: (t3 at: 2).
t5 := t4 deQuienSoy.
t6 := (self losJugadores at: t5) miColor.
t4 redrawInColor: t6].
self
playerTurn: (t1 at: 7)
Forget Spanish and concentrate of what matters, how send objects at your
will across net.
PS: Someone on list say rST methods don not should go in Socket , check
previous mail about this .
Edgar
More information about the Squeak-dev
mailing list
|