 SYMBOL: local-node
 
 : handle-node-client ( -- )
-    deserialize
-    [ first2 get-remote-thread send ] [ stop-this-server ] if* ;
+    deserialize [
+        first2 get-remote-thread send handle-node-client
+    ] [ stop-this-server ] if* ;
 
 : <node-server> ( addrspec -- threaded-server )
     binary <threaded-server>

: start-node ( addrspec -- )
    <node-server> start-server local-node set-global ;

TUPLE: remote-thread node id ;

C: <remote-thread> remote-thread

: send-remote-message ( message node -- )
    binary [ serialize ] with-client ;

M: remote-thread send ( message thread -- )
    [ id>> 2array ] [ node>> ] bi
    send-remote-message ;

M: thread (serialize) ( obj -- )
    id>> [ local-node get insecure>> ] dip <remote-thread> (serialize) ;

! Copyright (C) 2005 Chris Double. All Rights Reserved.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs concurrency.messaging
continuations destructors fry init io io.encodings.binary
io.servers io.sockets io.streams.duplex kernel namespaces
sequences serialize threads ;
FROM: concurrency.messaging => send ;
IN: concurrency.distributed

<PRIVATE
