
                        Socket Script Tutorial
                        ----------------------

The best way to learn Socket Script is to look at the examples and to
read the SScript manual. As a starting point however, I'll show you how
to make the usual 'Hello World' program with SScript. But since SScript
is networking-oriented, we'll make a client-server 'Hello World'. First
of all we'll make a server-oriented script that will send the 'Hello
World' message to anyone connecting, then we'll make the client-oriented
script that will connect to the server.

You can name the server 'sscript.hello-server' and start the SScript
composer this way:

sscript -c sscript.hello-server

You can also edit your script in a normal editor also if you don't want
to use the composer.

The first line you need to add to the script must have the 'server'
command. Then, the 'port' command will say which port the server will
listen to. This is the full header of the sscript.hello-server script:

server 0 ;
port 1800 ;
debug 0 ;
chop 0 ;
virtual 0 ;

The server command is followed by a 0 since we need a server-oriented
script. The port we will listen to is port 1800. We don't want debug,
line chopping or virtual address binding.

Then, we simply tell them to print 'Hello World' to anyone connecting:

write Hello World !
exit ;

The write command will send that string to anyone connecting to port
1800, and then SScript will exit.

That was pretty easy for a server-oriented script. Here is the whole
script again:

server 0 ;
port 1800 ;
debug 0 ;
chop 0 ;
virtual 0 ;
write Hello World !
exit ;

Now let's do the client side. You can name it sscript.hello-client and
use either the composer or the editor of your choice to edit it.

The header is very similar, but we say which IP address we want SScript
to connect to rather than 0:

server 127.0.0.1 ;
port 1800 ;
debug 0 ;
chop 0 ;   
virtual 0 ;

Here the IP '127.0.0.1' means localhost. So when we run the server
script, the client script will try to connect on the same system it is
running on. then, we simply read one line from the server, print that
line to the screen, and exit:

read 100 ;
print $string 100 0
exit ;

The 100 after the read command is the variable number in which we save
the line we get from the server. You have a total of 1000 variables,
from 1 to 1000, in which you can save strings or numbers. Then, the
print command prints everything in variable 100, from word number 0.
After this is done, we quit.

Here is the whole client script again:

server 127.0.0.1 ; 
port 1800 ;
debug 0 ;
chop 0 ;
virtual 0 ;
read 100 ;
print $string 100 0
exit ;   

That was pretty easy too. To test them, you can now start SScript to run
the server script, and then the client script:

./sscript sscript.hello-server
./sscript sscript.hello-client

And there you go!

To learn more about SScript, check the examples and the documentation.
