Did you try to learn TCP/IP in other languages and found it was a huge learning curve? In Rebol it’s not as hard even if you’d never coped with network programming before. Why? Because Rebol claimed to be a messaging language so everything relating to networking should be easy and indeed it is. Here’s a simple demonstration of a TCP Server and a TCP Client.
Launch a Rebol’s Console Copy and paste this server script:
myport: open tcp://:8000
forever [
print "waiting for connection ..."
wait myport ; wait as long as no client connects to the server
;a client has connected
print "connection detected"
connection: first myport
buffer: make string! 1000
read-io connection buffer 1000
print "sending a response"
probe buffer
insert connection rejoin ["Received " {"} buffer {"}]
print "closing the connection"
close connection
]

Launch ANOTHER Rebol’s console and copy and paste this client script:
try [
myport: open tcp://localhost:8000
insert myport ask "message to send: "
response: make string! 2000
while [
data: copy myport
][append response data]
print response
close myport
ask ""
]

Then enter “Hello from Client1″ (you can launch as many Rebol’s consoles as you want for clients) and validate.
The server should respond by printing on its screen:

And the client should print on its screen:

That’s all Folks !


















Re: TCP/ip client server eample
Client dies after sending first message.
Multiple clients do not seem to work as you implied.
Can you send me your scripts on reboltutorial a t yahoo.com ? I tested on Windows with RebolView 2.6 (the screencopies are taken from true test), on what platform and what version are you ?
Hello admin,
one question about tcp port in REbol.
I read in the documentation that Port is a series. however it doesn’t seem
to behave like a series.
e.g if you have
myport: open tcp://:8000
forever [
print "waiting for connection ..."
wait myport ; wait as long as no client connects to the server
connection: first myport
print first connection
print connection
close connection
]
my client script in rebcore console
remote1: open tcp://localhost:8000
insert from remote1 “test”
print first connection and print connection are two different things. can
you explain the port how it works. Is it really a series ?
does “wait myport ” return anything . what does “wait” return ?
you can even try it with 2 “print first connection” statement to see what you
get. It’s really confusing to me.
print first connection
print first connection
thanks in advance for your help.
pls note I haven’t included my email address . hope you don’t
mind.
Hi,
I’m not rebol Guru but try to answer as much as I can
myport is an object, you can look at it with
write clipboard:// mold myport
or
write %myport.txt mold myport
It’s not series but it can use pick, insert etc. as if it was.
May rewrite this tut in the future to better explain.
If you need more advanced answer you can find the Rebol Gurus on Altme or Rebol mailing
http://reboltutorial.com/blog/rebol-community/