I'm making a little game in rebol (internet scrabble, currently in Swedish
but could of course easily be translated if somebody is interested :) that
requires two rebol scripts to message each others.

Easy in theory. In practice, they close connection after a number of
messages. I have no idea why. :(

Here's some testing code. If I run this twice and enter 127.0.0.1
(connecting to myself) it sends a total of 121 messages, and then one of
the scripts refuse to accept a connection. I sent it to someone else, there
it made 117 messages or so. But always the same number on the same system,
it seems. I can't really explain this. What am I doing wrong?

REBOL
[Title: "netmsgtest"
 Date: 2000-04-17
 Author: "Johan R�nnblom"
 Purpose: {try to get two rebolscripts to message each other}]

connect: func []
[either error? try [client: open to-url rejoin ["tcp://" otherurl ":8000"]]
 [clienturl: to-url rejoin ["tcp://" otherurl ":8001"]
  server: open tcp://:8000
  mode: "server"
  running: receive]
 [insert client mold "connected"
  close client
  clienturl: to-url rejoin ["tcp://" otherurl ":8000"]
  server: open tcp://:8001
  mode: "client"]]

transmit: func [msg]
[if error? try [client: open clienturl]
 [print "Connection closed." close server quit]
 insert client mold msg
 close client]

receive: func []
[inmsg: do copy first server
 if inmsg = "exit" [close server quit]
 return inmsg]


otherurl: ask "Enter remote url: "

connect
if mode = "client"  [transmit "1"]

forever
[a: receive
 print a
 b: (to-integer a) + 1
 transmit b]



-- 
  /Johan R�nnblom, Team Amiga

Stop worrying so much about this. In the worst case we'll die.


Reply via email to