What is the smallest simplest example script for "port" .
Hopefully something that shows off how easy it is to connect two computers and send information back and forth. Perhaps a file. Although a message system is ok too of course.
Something like this? Run once as server, then again as client.
role: ask "Run as [C]lient or [S]erver? "
if role = "s" [ port: tcp://:9090 server: open/direct/no-wait port wait server client: first server print "Client connected." forever [ wait any [client .01] if msg: copy client [ print [now/precise msg] insert client "pong" ] ] ]
if role = "c" [ port: tcp://127.0.0.1:9090 server: open/direct/no-wait port forever [ insert server "ping" if msg: copy server [ print [now/precise msg] ] wait .1 ] ]
The WAITs in mine aren't needed, just there to slow things down a bit for human consumption.
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?
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
almost done, but I've got an errand to do, will be back with the solution in about 1h30
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.