This post details a winsock interface library I am playing with. If you are not interested in network programming with Kix stop reading now 'cause you will find this a long and boring post.

This first attempt at giving KiXtart access to network sockets uses the free SocketWrench objects available from Catalyst. You can download them from the Catalyst seb site, and indeed you will have to if you want to play with these script. (thanks to Bryce for finding these)

I had no luck with the 16-bit version, so I suggest you use the 32-bit.

The routines are abstracted in a Kix library. This means that applications may be developed independantly, and when a newer version of the library comes along you just need to replace the library without affecting the application. It also means that someone else can develop a library for a different winsock control, and as long as they use the same function names and parameters it will simply work as a drop-in replacement.

I've included two Kix scripts here. One is the library called "wsctlyst.kix" to interface to the Catalyst socket control. At the moment I've only coded "server" type functions:
  • SOCKETOBJECT udfWSLIBMakeListener(INTEGER PortNumber,Optional INTEGER SocketType)
    : Create a listener on port PortNumber and return a socket object for it. @ERROR is set if the socket cannot be created.
  • STRING udfWSLIBGets(SOCKETOBJECT Socket, Optional BOOLEAN WaitFlag)
    : Return a newline delimited string from the socket. If WaitFlag is zero or not present the function will wait (permanently) until it gets a string - this behaves like the Kix GETS() function. If WaitFlag is set to "1" the routine will return immediatley if no string is available. To differentiate between a blank string and no string available, if @ERROR is zero then there is a valid string (even if blank). If @ERROR is set and the string is blank then there is no string available (it is not an error). If @ERROR is set and the returned string is not blank then an error has occured. I set the WaitFlag in the sample application so that the user at the server can disconnect or close the server down even if the program is waiting for a command from the remote client.
  • VOID udfWSLIBPuts(SOCKETOBJECT Socket, STRING Output)
  • VOID udfWSLIBCloseSocket(SOCKOBJECT Socket)
    : Send a string to the socket. You must include carriage returns and line feeds if you need them
Ok, that's the boring bit out of the way for the moment. So what does a working sample look like? Here is a log of a session using the demo remote control application. I have telnetted from one of my DG Unix hosts to my PC...
code:
# uname -a
dgux purdy R4.20MU04 generic AViiON Pentium
# telnet 10.9.2.134 10000
Trying 10.9.2.134...
Connected to 10.9.2.134.
Escape character is '^]'.


REMCTL.KIX REMOTE CONTROL DEMONSTRATION SCRIPT
----------------------------------------------


TOP LEVEL MENU
--------------
1: Information Submenu
2: Run Abritrary command

q: Close Connection

Choose an Option: 1

INFORMATION MENU
----------------
1: Server identity
2: Server KiXtart info

3: Client IP info

q: Return to previous menu

Choose an Option: 1
Server Identity Information
---------------------------
Remote Control Version : 1.00a
Server OS Type : Windows 95
Server OS Suite :
Server IP Address : 10. 9. 2.134
Server Name : richardhowarth.xx.yy.com
Server Current Time : 13:15:54
Hit <Enter> to return to menu:

INFORMATION MENU
----------------
1: Server identity
2: Server KiXtart info

3: Client IP info

q: Return to previous menu

Choose an Option: 2
Server KiXtart Information
--------------------------
KiXtart Version : 4.00
WSLIB Version : 1.00a
WSLIB Last Updated : 27 September 2001
WSLIB Description : wsctlyst.kix: Wrapper for Catalyst Winsock Control
WSLIB Maintainer : Richard Howarth
WSLIB Maintainer Email : rhowarth@sgb.co.uk
WSLIB Maintainer Phone : Not Supplied
Hit <Enter> to return to menu:
INFORMATION MENU
----------------
1: Server identity
2: Server KiXtart info

3: Client IP info

q: Return to previous menu

Choose an Option: q

TOP LEVEL MENU
--------------
1: Information Submenu
2: Run Abritrary command

q: Close Connection

Choose an Option:2
Enter command to execute and hit return
The server process will hang if user input is required.
Only output that can be captured with DOS redirection
using '>' will be displayed.
Enter blank command or 'q' to return to menu
> net config
Command execution started at 13:19:54
Command execution completed at 13:19:55
Command error status: 0
----- START OF OUTPUT FROM COMMAND -----
Computer name \\RICHARD HOWARTH
User name RHOWARTH
Workgroup XXX
Workstation root directory C:\WINDOWS

Software version 4.00.950
Redirector version 4.00
The command was completed successfully.
------ END OF OUTPUT FROM COMMAND ------
> DIR
Command execution started at 13:20:40
Command execution completed at 13:20:41
Command error status: 0
----- START OF OUTPUT FROM COMMAND -----

Volume in drive D is DATA
Volume Serial Number is 1604-1629
Directory of D:\KIX2001\wsocklib

. <DIR> 26/09/01 9:34 .
.. <DIR> 26/09/01 9:34 ..
WSCTLYST KIX 8,275 27/09/01 12:27 wsctlyst.kix
SAVE <DIR> 27/09/01 10:51 save
REMCTL KIX 9,575 27/09/01 12:10 remctl.kix
8 file(s) 239,884 bytes
3 dir(s) 902,529,024 bytes free
------ END OF OUTPUT FROM COMMAND ------
> q

TOP LEVEL MENU
--------------
1: Information Submenu
2: Run Abritrary command

q: Close Connection

Choose an Option: q
**Disconnecting at your request**
Connection closed by foreign host.
#

Not bad eh! A remote control application written in KiXtart.

Before you download and install these scripts be aware that the arbitrary command menu option is exactly that - it will run a command in the local context on the server. As there is no password control (yet [Wink] ) anyone could telnet to your machine and run a destructive command. So don't test it in a production environment [Eek!]

The scripts are quite large (about 8/9k), so I'm not going to include them here. Download them from:
wsctlyst.kix : winsock wrapper library functions
remctl.kix : Remote control demo application
It also means you'll be sure to get the latest versions if I make a change.

Let me know what you think of what's there now. If there is enough interest I'll code up the client side and add features.

PS I know I've mispelled "arbitrary" on the menu. It will be my first bug fix, heh.

[ 18. July 2003, 11:55: Message edited by: Richard H. ]