Author Topic: ssockets compile  (Read 15524 times)


  • Guest
ssockets compile
« on: August 23, 2011, 11:56:14 PM »
I have made a successful ssockets compile.  The example programs all execute ok.

The Simple Socket library is used with the programming language ScriptBasic. It provides elementary access to TCP Streaming and RAW Sockets.

Complied on Ubuntu11 using SB_2.1RC1_Linux Scriptbasic package for the scriba source.

SSOCKET::DEBUG(int flag)

Description: Enables or disables debug messages to the console. If flag is '1' the debugging is enabled, else it is disabled.

Example: SSOCKET::DEBUG (1)


Description: Show the current Simple Socket version on the prompt.


SSOCKET::CONNECT (string hostname, int port)

Description: Connect to the specified server and port. You can enter a hostname which will be resolved automatically by the Simple Sockets library. An IP address is also possible, but this address has to be entered as a string. The function returns the socket number to the BASIC program. If the returnvalue is < 0 an error has occurred. The following errors are possible:
-1 : Host does not exist
-2 : Cannot setup the socket
-3 : Cannot connect to the specified socket

Example: socket = SSOCKET::CONNECT ("", 40000)


Description: Disconnects the specified socket.

Example: SSOCKET::DISCONNECT (socket)

SSOCKET::CHECK (int socket)

Description: Checks if a socket has new information. This command can prevent endless waiting when reading off a socket. First do a check, and if the returnvalue is '1' (TRUE) then proceed with reading or accepting.

Example: IF SSOCKET::CHECK(socket) THEN PRINT SS_READ(socket)

SSOCKET::READ (int socket, int flag)

Description: Reads information off the socket. If the flag is SS_STREAM, it returns a string with the information read. If an error has occurred, the string can contain the following values:
“SIMPLE SOCKET ERROR 1" : Cannot read from socket
“SIMPLE SOCKET ERROR 2" : Remote side has closed the connection

If the flag is SS_RAW it returns a reference pointer to a block of RAW TCP data. This pointer has a cyclic value, varying from 0 to 63. If an error has occurred, the returned number can contain the following values:
-1 : Cannot read from socket
-2 : Remote side has closed the connection

Example: dat$ = SSOCKET::READ(socket, SS_STREAM)

SSOCKET::WRITE (int socket, data, int flag)

Description: Write text to the specified socket when the flag is set to SS_STREAM. Write RAW TCP data to the specified socket when the flag is SS_RAW. The RAW data is identified by a reference pointer, retrieved with SSOCKET::READ. After the WRITE the amount of bytes written to the socket is returned. It may be the case that not all bytes have been sent. This should be checked by trial and error. If not all data can be sent at once, divide the data in smaller chunks.

Example: sent = SSOCKET::WRITE(socket, "Hello everyone!", SS_STREAM)

SSOCKET::GETRAW (int pointer, int flag)

Description: Get the RAW network traffic identified by 'pointer'. The value of this parameter must contain a reference pointer to the RAW data, and is set by SSOCKET::READ in the RAW mode. The flag determines if the result will be beautified (SS_TRUE) or not (SS_FALSE). The beautification is realized by omitting all ANSI codes lower than 9 and higher than 126. It is strongly recommended to use this command after the RAW data block has been used for other purposes, since the beautification might change the RAW data.


SSOCKET::SERVER (string hostname, int port, int maxconnections)

Description: Sets up a server on the specified hostname and port. Since a computer can have more ethernet interfaces a hostname or IP address have to be specified. Also the maximum of allowed connections to the server must be filled in. The command returns the socket number to which clients can connect. The actual communication with clients is done on another socket, see the command 'SS_ACCEPT'. If a value below zero is returned, an error has occurred:
-1 : Specified host does not exist
-2 : Cannot connect to socket
-3 : Cannot configure socket
-4 : Unable to bind the specified socket address
-5 : Unable to listen to the specified socket address

Example: server_socket = SSOCKET::SERVER(“", 40000, 5)

SSOCKET::ACCEPT (int socket)

Description: When the server has checked the socket for changes (with SS_CHECK), an accept of a connection can follow. This command returns the newly formed socket with which the client will communicate. If the value '-1' is returned, there was no connection possible.

Example: IF SSOCKET::ACCEPT(server_socket) > 0 THEN PRINT “Call accepted!"


Description: When the server has accepted an incoming connection, the Simple Sockets module keeps track of the IP address from which the connection was made. A string with this IP address is retrieved with this command.


SSOCKET::B64_ENCODE (string text)

Description: This command converts a string to a BASE64 string. The result of the conversion is returned to the BASIC program.

Example: PRINT SSOCKET::B64_ENCODE("Hi there!")

SSOCKET::B64_DECODE (string text)

Description: This command decodes a BASE64 string to human readable text. The result of the conversion is returned to the BASIC program.

Example: a$ = SSOCKET::B64_DECODE("SGkgdGhlcmUh")
« Last Edit: August 24, 2011, 12:13:15 PM by RONB »


  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: ssockets compile
« Reply #1 on: August 24, 2011, 12:24:53 AM »
That is one of Peter 's sites when he was a big fan of ScriptBasic. He went on to write his own Basic to C tranlator for Linux/Mac and left anything ScriptBasic related in AS IS status. His motivation for writing his own Basic was he wanted a 64 bit version of Basic running on TrueUnix/Linux but translated to C. He wrote his first version of the translator in the bash shell scripting language. If he would have assumed ScriptBasic would compile in a 64 bit environment, maybe BaCon would have never been written.I have been looking for an simple way to use scriba as a TCP server. Thanks for the reminder about Peter's ScriptBasic sockets contribution.
« Last Edit: August 24, 2011, 12:47:31 AM by support »