AltME: Rebol School

Messages

Gregg
Or there are slightly more involved examples out there. Like http://www.rebol.net/cookbook/recipes/0028.html
The WAITs in mine aren't needed, just there to slow things down a bit for human consumption.
Reichart
In these examples, it is assuming a server and a client, as opposed to two clients, and then a way to get them to find each other?
Maxim
either attempt[port: open tcp://:33101] [
    print "Running as server^/----^/"
    forever [ probe copy client: first wait port   close client]
][
    print "running as client^/----^/"
    forever [ insert (server: open tcp://localhost:33101) ask "message to send: "  close server]
]
a much simpler server/client example...
am building a google wave equivalent peer to peer example using console port... should be ready in a few minutes

Maxim
almost done, but I've got an errand to do, will be back with the solution in about 1h30
Reichart
:)
Maxim
I had a LOT of fun building this... its not perfect (backspace and delete cannot function in this mode cause I am not storing the console's screen buffer, but it goes a long way with just 40 lines... the vast majority of the code is actually managing the console's low level port interface.
rebol []
either attempt [lcl-port: open/lines tcp://:33101] [
    rmt-port: 33102
][
    lcl-port: open/lines tcp://:33102
    rmt-port: 33101
]
con: open/binary [scheme: 'console]
remote-port: none
digit: charset "0123456789"
forever [
    p: wait [lcl-port con]
    either p == con [
        key: first con
        either key = 27 [
            read-io con io: head clear "" 3
            cmd: copy "K [27 "
            foreach c io [ append cmd to-integer c append cmd " "]
            append cmd "]^/"
            chars: join "^[" io
        ][
            cmd: rejoin [ "K " key "^/" ]
            chars: to-char key
        ]
        
        insert ( rp: open rejoin [tcp://localhost: rmt-port] ) cmd
        close rp
    ][
        cmd: first first lcl-port
        parse cmd [
            "K " here:
            "[" (chars: to-string to-binary load here)
            
            | ( chars: to-char load here )
        ]
    ]
    prin chars
]
basically, store the script and run it twice,  both consoles are linked as if you where typing in anyone of them.  type in any of the two, and the other types the same thing!
we could modify the script a little to make it work across two different machines.  in that case, instead of changing the port number, we'd change the remote ip address instead.
DocKimbel
Instead of:
    insert ( rp: open rejoin [tcp://localhost: rmt-port] ) cmd
    close rp
you could use simply:
    write rejoin [tcp://localhost: rmt-port] cmd
Gregg
That's very cool Max.
Reichart, you just asked for smallest and simplest. :-)
Maxim
doc, yeah, true, I forgot we could use write on tcp ports.
for those who did not try the above script... do it (in 2.7.8) its pretty fun.
Reichart
"we could modify the script a little to make it work across two different machines.
That is the KEY, add that :)

Gabriele
Arnold
Johnk replied pointing to so chat, where my answer is too. Not going to subscribe to yet another site, there's too many already.
I have another nice question. I have 6 integers from 0 to about 23000 and I like to hash these. I calculated the 6 integer would fit into 96 (3 x 32 bit) bits. Any FUN ideas on howto do this?
Gregg
What is the context and the goal?

Arnold
The context is creating a Chinese chess game. I divided the board into 6 equal pieces and use the fieldcode and piece to calculate a number, I took some precautions that should make it unique. For the startposition the values are hash-1: 1508 hash-2: 2232 hash-3: 1508 hash-4: 1802 hash-5: 2293 hash-6: 1802, When I calculate for a maximally filled area there is an upperbound of approximately 23000. But I think in practice it could always be under 8000.
I could have gone the easy path and copy existing C programs using the bitboards and corresponding Zobrist hashing functions. But the easy path is boring and leads nowhere too ;-) So I decided to play around & find out an alternative way.
Arnold
I will have to shuffle my multiplication factors a bit more for now a black king of value 129 can be placed on a field with factor 115 giving 14835, that is a bit too much of a good thing :-)

Last message posted 184 weeks ago.