tcpip_thumbDid 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
]

tcpip_server

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 ""
]

tcpip_client

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:

tcpip_server_received

And the client should print on its screen:

tcpip_client_received

That’s all Folks !

Bookmark and Share

Recent Articles