OpenSock

van der Vegt.nl

OpenSock for Asymetrix Toolbook


Download and Version History:

Version 1.2c is available, although i still have to finish the documentation and   rework the demos.


I've also provided a mtb40 version of the widget book. I'll be working on an integration of the widget property editor and the online help for that version. I had to leave out the rasdial widget because it's a 32 bits dll i used. I'll look into the 16 bits version when i have some time and find a suitable sample in c or delphi to determine the value some hard to get constants.


I've left out the samples this time because i have to redo them with new scripts (and yes, i know that my spare time is limited too).


Last thing i want to work on is the udg mode winsock applications can use to setup connections. I plan to implement the TFPT protocol (which is a very lightweigth file transfer protocol that looks a bit like good old xmodem).


Currently Opensock can:

  • Send e-mail including binary attachments of unlimted size
  • Retrieve e-mail (bound to a 64k limit per e-mail due to using toolbook ;-)
  • Retrieve (binary) files from http server
  • Can, mimic a ftp server including real or simulated filesystem
  • Request time from a ntp time server
  • Retrieve book properties over the internet
  • Delivers a toolbook 1.5 alike command window over the internet
  • Implement chat server/client
  • Emulate basic internet services like discard, chargen, qotd and echo
  • Lookup dynamic ip addresses
  • Create a full blow webserver with real or simulated content and support for binary files and authentication
  • Transform toolbook drawings on-the-fly into into vrml worlds
  • Have a feedback dialog e-mail the feeback directly to you
  • Check for updated versions/content of your software of content on the web
  • And (off-course) much more (if you're a bit of a creative person).


Good suggestions, discard the idea that content should be on disk or existing at all.With toolbook you got the full programming power of Toolbook to generate whatever contents a client application need to be fooled into thinking what you think it needs to see. Furthermore OpenSock lets you use the internet to your advantage from within toolbook. With Opensock you can e-mail without depending on a particulair brand of web browser being installed, all well contained from within your application.


So USE internet,

don't let internet use you.


If you got any questions or good ideas about opensock, feel free to e-mail me.


Version History


version 1.2c (tb-ii/5) or version 1.2c (mtb40)

  • Added final data processing in fdclose handling.
  • Added a http request widget that allows you to fetch a (binary) file from a http server (which is
    handy for neuron in insucure mode).
  • Corrected a winnt releated bug in the data size reported to the fdread callback handler.
  • Added support for a widget that retrieves dynamic ip addresses from the machine it's running on.
  • Ported the widget catalog back to mtb40 (but had to leave out the rasdial widget)


version 1.2a (preview)

  • Version number changed to 1.2.
  • Added a small services file into findservice, so this function will always work for the most populair services.
  • Added fdwrite to callback functions, to further complement the package. Not very usefull though.
  • Removed bug in OS_startservice_deamon.
  • Most samples ported to Toolbook II widget model (or Extended Objects as they will be called in the upcoming version 6.0)
  • Added 'OS_locatewidget' handler
  • Added 'OS_scanforproperties' handler


version 1.0e (internal)

  • Version number changed to 1.0e
  • Made mode a socket property, so sockets can all operate in their own mode. Incoming connections will inherit the mode of the listening socket.
  • Mode is now optional parameter for OS_startport_daemon and OS_startservice_daemon.
  • Mode still defaults to "line" for OS_startport_client and OS_startservice_client.
  • Removed WO_* property clearing from OS_linkdll, a beta leftover
  • Added OS_setdefaultmode for setting a default mode. If you do nothing, the mode will default to "line"
  • It's now possible to work default in line mode, but listen for raw binary connections too. Needed for ftp and other binary protocols.


version 1.0d (internal)

  • Version number changed to 1.0d
  • Added sntp (simple network time protocol) client, using raw mode
  • Added basic web server client, using line mode
  • Fixed memory leak in OS_connecttoport
  • Changed linger options in OS_Winsock/FD_ACCEPT to minimize memory leakage.
  • Added OS_peekbuf to look in buffer before a crlf arrives
  • Implemented a first version of fast decoding. Must still be optimized....
  • Added fdread callback
  • Added OS_setmode handler to set the parsing mode of received data to raw,line or char, raw will call fdread callback, line and char will call line_received callback.
  • OS_setmode can combine raw with line or char.
  • Fixed a problem with line mode & telnet connections
  • Changed SOCKET_ERROR from -1 into 65535 due to sign errors
  • Changed OS_inbuf to re-usable one like in "new.tbk"
  • Linked tbkxxwin.dll according to sysversion (xx=40 or 50)
  • Added conditional init to start_ handlers
  • Added/updated some comments
  • Changed OS_storage_index to a utility handler by passing it the array by reference. Only problem is the initial size of the 2nd dimension.

  • Performed performance & stability tests:

CPU

Internal memory

Local browsers

Remote browsers

Request size

Speed

Throughput

DX2-66

20 Mb

1 x IE4

20kb

0.4 req/s

8kb/s

P133

80 Mb

up to 3 x IE4

up to 3x IE4

20kb

4-5 req/s

80-100kb/s

P200pro

64 Mb

todo

todo

20kb

?

?

version 1.0c

  • Version number changed to 1.0c
  • Fixed a small bug in backspace handling.
  • Added first version of start client handlers, simplifying starting clients by hiding more details.
  • Fixed a bug in OS_conecttoport, host address=dword instead of a longint. (thanks to Dan Tasota)
  • Start changing type of socket from INT to WORD.
  • Debugmsg sent by this script now have socket number 0 Fixed some errors/ommisions in the script's comments
  • Made the OS_inbuf dynamic of size, (OS_maxsockets-1) so the dimension is 255 for Win95 and 65535 for WinNT4
  • Clearing & initializing of OS_inbuf moved to OS_startup as that's the place where the max number of sockets is retrieved.
  • Changed type of cmd parameter of ioctlsocket from LONG to DWORD
  • Added resolved ip address&port number of other side to debugging output and OS_peername, a wrapper around the winsock function.
  • Updated documentation in OpenSock.doc Added OS_shutdown handler
  • Changed return type of socket from INT to WORD
  • Added OS_shutdown handler
  • Added resolved ip address&port number of this side to debugging output and OS_socketname, a wrapper around the winsock function GetSocketName. This function is needed for multiple servers inside one book to retrieve the port number of the notification.
  • Added version number to debbugging output
  • Changed PointerInt's to PointerWord due to continuing problems with C's lack of checking range check errors on integers.
  • Changed the inbuffer to a 2 dimensional array due to the the fact that WinNT 4 has a maximum of 65536 sockets.
  • Added an update application to update shared OpenSock scripts in all demos.
  • Added a guestbook sample that stores guest data in itself and also shows how to program more than one webserver in a single toolbook object.


version 1.0b

Added first version of start server handlers, simplifying starting servers by hiding more details. Never released.


version 1.0a

Initial release to ftp.asymetrix.com and the TB II developers corner news at www.asymetrix.com.


Current uptime on P133 more > 10 days and > 5.7M hits


Other Tools


LZExpand

This book shows how to use the LZexpand API to decompress files. LZexpand decompresses files (on file by file basis, so not archives like zip files) compressed with compress.exe. Compress is a microsoft utility, part of the NT resourcekit. I don't know if it's available for free somewhere.

The demo needs a book called test.tbk compress to test.tb_. This can be done with COMPRESS -r test.tbk or COMPRESS test.tbk test.tb_. The NT version seems to work fine under windows 95 too.


TBCapture

A wrapper to show live video from a windows imaging device under windows 95. It wraps around the video for windows capture Api. It's only tested under windows 95 and is extremely sensitive to toolbook dialogs popping up over the video capture window (if the video stop, windows will most likely reboot without any warning, delay or question (= a crash).

Besides showing video on top of a stageobject that function as a placeholder this demo also contains code to grab video images and paste them back into toolbook as either a image or in a richtext field.


TBConsole

Equips toolbook with a console window. It runs under both windows 95 and windows NT 4.0. A console window looks like a dosbox, but one that can be written and read from by toolbook. So toolbook can emulate for instance a legacy application including key and mouse handling.

It runs fine under windows 95 unless you press either CTRL-C or CTRL-BREAK in which case toolbook will crash (although the API says it shouldn't). Windows NT 4.0 preforms much better and lets toolbook handle the CTRL-C and quits (very fast, but clean) if CTRL-BREAK is pressed.


TBDao

DAO is short for Database Access Object and is a microsoft product that comes with a lot of new Microsoft products like msoffice 97. It simplifies database access and gives access to the msaccess jet engine and has a backdoor to ODBC databases too. The DAO engine itself is a OLE32 control that is access by TBdao through an 32 bits mfc 4.2 dll written in Microsoft Visual C++ 5.0 (SP3).


The Toolbook-II demo that can be downloaded is a fully functional dll that can retrieve info from an access database demo called advworks.mdb. All files should be copied into one directory. The TBdao demo only supports reading the database and retrieving infromation about the database like fieldsizes, names and types. Modifying the database is what I'm curently working on.The TBdao dll is a debug build and doesn't contain a lot of checks yet (like if the database really exists), so may crash in which case win95 has to be rebooted.

DAO works by defining a workspace that can contain a number of databases (for example mdb files). Each database in it's turn can contain a number of recordsets (SQL queries) that can be read.


Through attached tables or external datasources dao should be able to read dbase files, excel spreadsheets and paradox tables too. It also provides a backdoor to ODBC called ODBCdirect so there is a possibility that you can access SQL server and Oracle too.


Under windows NT 4 the dll has more features like being able to update and add records to a database. This due to the fact that 16 bits apps are not allowed to start multiple threads in 32 bits dll's under win95 (seems to be a feature of win95 by design and not a asymetrix thingy). Dao is a multithreaded ocx control, altough it only seems to use additional threads when updating and adding record.


Lastest developments:

  • I updated the tbdao dll so it's statically linked to mfc instead of dynamically. That way it's easier to get the demo up and running. I also removed some debugging messageboxes and put my name inside the dll's.
  • The toolbook application now detects windows NT 4 and will show more features there.
  • I included the full source of the dll for those who have access to msvc 5.0. Please let me know if you do anything with it, as i like to hear it. 
  • Under windows NT 4.0 updating AND appending records works. The demo is changed a bit so it only will run the code for modifying the database only works when running under windows NT 4.0. Beware to unzip all three files into the same directory as there's no handling of missing database files etc yet in the script. The code still contains some debugging dialogs (sorry, but i still need them) and I've compacted the archive a bit for faster downloading.
  • I've succeeded in altering a record under windows NT 4 but keep having a bit of a problem with the same code under win95 (the update works but still throws an exception with a undefined errorcode).
  • I've also added a number of new functions to query database properties like number of tables etc.
  • I discovered that by design a 16 bits application under win95 is not allowed to create more than a single thread in
    a 32 bits dll. This is the reason update/append won't work under win95. Winnt4 doesn't have this limitation.


TBPower

This sample shows how to obtain information from the APM system (Advanced Power Management). It can retrieve info like is this computer hooked into the AC line or is it battery powered and if so, how long do the batteries last.

The program also contains a sample of how to interact with suspend notifications (although i must confess canceling a users choice didn't work well).


Traybook

Equips toolbook with an icon in the systray area on the taskbar. The icon is controlled using OpenScript. It features a sample of how to change the tip (pop-up text) and how to translate it;'s window messages so you can have contextmenus on the trayicon. The result of the menus (which are stored as resource inside toolbook) is handled by toolbook messages, just like normal menus. To remove the main icon from the taskbar it's neccesary to hide the mainwindow instead of minimizing it (otherwise it will still have a large icon). A sample of that is also in the TrayBook.


TrayBook hasn' t been tested yet under windows NT 4, but runs fine under windows 95 osr2 with IE4.01 with shell extension.