#59334 - 2001-09-27 03:42 PM
[LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
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 ) anyone could telnet to your machine and run a destructive command. So don't test it in a production environment
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. ]
|
Top
|
|
|
|
#59337 - 2001-09-27 05:04 PM
Re: [LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Heh,yeah, sexy innit.Of course you can't deal with binary characters, but simple email, syslog recording etc will be fine. I used RC3 for testing, and I develop on our lowest common denominator - my Win95 machine. I dunno why kbhit() would hang - most peculiar. You don't need that small loop - it is just there to provide a clean shutdown, and to allow you to close the client without stopping the server. Try commenting it out. PS: Updated version with simple password control uploaded.
|
Top
|
|
|
|
#59338 - 2001-09-27 05:08 PM
Re: [LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Oh my ... this works like a charm ...code:
# # telnet xxx.xxx.28.49 10000 Trying... Connected to xxx.xxx.28.49. 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 NT Workstation Server OS Suite : 0 Server IP Address : xxx.xxx. 28. 49 Server Name : fr91016224.xx.xxx.xx Server Current Time : 09:52:22 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: 3 Client IP Information --------------------- Your IP Address : xxx.xxx.28.164 Your IP Port : -16045 Your Name (Unreliable) : dn1cro.xx.xxxx.xx 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 > dir Command execution started at 09:52:32 Command execution completed at 09:52:32 Command error status: 0 ----- START OF OUTPUT FROM COMMAND ----- Volume in drive G is DEVELOPMENT Volume Serial Number is 1F24-1DF4 Directory of G:\kixnet 01/09/27 08:52a <DIR> . 01/09/27 08:52a <DIR> .. 01/09/27 08:53a 8,275 wsctlyst.kix 01/09/27 09:47a 9,575 remctl.kix 01/09/27 08:56a 5,778,432 sw35fe32.exe 01/09/10 10:14a 196,608 kix32.exe 6 File(s) 5,992,890 bytes 269,844,480 bytes free ------ END OF OUTPUT FROM COMMAND ------ > 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.
I must say - this is very well done. Your scripts are very professionally written and they work a charm ... some notes from over here : 1) I tried installing SocketWrench on Windows 2000 pro, but the install hung on the last bit - registering the components ... One can (should) be able to manually register the control with regsvr32.exe though ... I'll try it later (I moved over to my NT box ) ... 2) In case anyone didn't notice (I didn't right off the bat) the remctl.kix script requires KiXtart 2001 RC3 (your use of the KBHIT() function) ... you just demonstrated how usefull this function will become ... The mind boggles ... -Shawn
|
Top
|
|
|
|
#59339 - 2002-08-03 08:30 PM
Re: [LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Bryce
KiX Supporter
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
Richard....
have you done any more work with this?
I have tried to take a gander at this, but all of the examples are for VB, and frankly.... i am lost
Bryce
|
Top
|
|
|
|
#59340 - 2003-07-17 09:12 PM
Re: [LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Bonji
Starting to like KiXtart
Registered: 2001-09-28
Posts: 169
Loc: Virginia
|
I'm bringing this thread back to life...
I've worked with the Socketwrench stuff some and specifically by utilizing Richard's test scripts. I decided to port the script to Kixforms and got that completed. Let me know if anyone is interested in that code, and I'll post it.
But I have a couple of questions I would like some assistance with...
1) Is there any way I can listen for connections and not block so that I may perform functions on the server side while listening?
2) How can I set it up so that I can connect multiple clients to one server?
3) It looks like the socketwrench library wants to take advantage of events, however I noticed in one of Howard's scripts he mentioned that these events cannot be supported in KiX. It seems to me that this limits the functionality of the socketwrench libraries.
All of my attempts at working through these problems have failed, however I am not very proficient with this tool yet.
Any comments/suggestions are welcome.
-Ben http://www.rgcweb.org/kix
|
Top
|
|
|
|
#59341 - 2003-07-18 11:04 AM
Re: [LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
I haven't looked at this in a very long time, and I don't have free time to look in any great detail, but you can play with the following things:
- Try setting the ".Blocking" property to false.
- Try polling the ".State" property.
- Try setting the ".ReuseAddress" property to true.
- Increase the "Backlog" property.
|
Top
|
|
|
|
#59343 - 2003-07-19 12:00 AM
Re: [LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
quote: You did say KixTart and noone did recognice
This was originally posted way back in Sep. 2001 before the Tart police were formed
quote: Is there or will there be the ability to have several (In my case up to 4 or more) scripts communicate 'directly' to each other?
Sure, but why bother? You can achieve the same thing much more easily and without a third party DLL by using remote registry read / writes.
|
Top
|
|
|
|
#59346 - 2003-07-18 01:28 PM
Re: [LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
Top
|
|
|
|
#59347 - 2003-07-18 01:30 PM
Re: [LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Well, use one that is
|
Top
|
|
|
|
#59349 - 2003-07-18 07:23 PM
Re: [LIBRARY] Kix2001 Winsock object interface library v1.00a
|
Bonji
Starting to like KiXtart
Registered: 2001-09-28
Posts: 169
Loc: Virginia
|
Thanks for the reply Richard. I tried changing the blocking setting, however it prevented the tool from listening. I'll try the other settings and see what I can come up with.
-Ben http://www.rgcweb.org/kix
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 264 anonymous users online.
|
|
|