Enclosed is the summary document on Socktalk. It provides an overview of the product, information about our demo program, the components of client-server application architecture and where Socktalk fits in, information about Windows Sockets and TCP/IP, a technical summary of the classes implemented, and a client-server programming example. ======================================================================= Aug 17/94 Socktalk - LPC Consulting Services page 1 LPC Consulting Services Tel no: 416-787-5290 937 Briar Hill Ave. Fax no: 416-787-9214 Toronto, ON M6B 1M1 CompuServe: 73055,123 Canada Internet: 73055.123@compuserve.com 1. Overview =========== Socktalk, the TCP/IP communications solution for Smalltalk/V, is a Windows Sockets (WinSock) compliant set of classes for Smalltalk/V for Windows, Win32 and Windows NT which interfaces to Windows Sockets compliant Dynamic Link libraries. It enables Smalltalk developers to deploy client server applications written entirely in Smalltalk. Socktalk supports both blocking (synchronous) and non-blocking (asynchronous) Windows Sockets applications. Note that while a Socktalk application is running in a "live" image, the developer can still continue work in the Smalltalk image. Socktalk comes with online help and sample programs which can be run against a remote server or a server process on a local machine. Full source code is included, and any executables developed using Socktalk can be distributed royalty-free. This document describes how Socktalk fits into a Smalltalk client-server implementation, the system requirements and software components needed, a technical summary of the architecture of Socktalk and the Smalltalk classes implemented, and sample code for a mini-application, Daytime Server. 2. What is Windows Sockets ========================== Windows Sockets (WinSock) defines a Network Programming interface for Microsoft Windows based on the Berkeley Software Distribution (BSD) sockets. It is supported by a number of network software vendors and is included as part of Windows NT. 3. Demo Program ================ We have a free demo which allows you to run a number of the sample mini-applications provided with Socktalk. A ZIP file containing this document you are reading, the demo program with the sample applets, has been posted on CompuServe in the 3rd party library of the Digitalk (GO DIGITALK) forum. Download file SOCTLK.ZIP (approx. 280K) for the Windows demo, or file SOCW32.ZIP (approx 252K) for the Win32/NT demo. Alternatively, send a checque or money order for $5.00 and we will send you a demo diskette. Please specify whether you need the Windows or Win32 version. If you have technical questions and online access, you can email the to Luc Charpentier at CompuServe user-id 72642,2217 or Internet address lucc@tor.hookup.net. Aug 17/94 Socktalk - LPC Consulting Services page 2 4. Client-Server Implementation ================================ The diagram below indicates where LPC Consulting's Socktalk fits in the client-server application architecture. Note that all application programming on both the client and server machines can be done in Smalltalk. CLIENT SERVER ====== ====== Smalltalk/V Smalltalk/V | | | | ********************** Windows Sockets ********************** * LPC Consulting * <---- Classes ----> * LPC Consulting * * Socktalk * <---- ----> * Socktalk * ********************** ********************** | | | | Windows Windows Sockets DLL Sockets DLL | | | | TCP/IP TCP/IP Protocol Stack Protocol Stack | | | | Network Interface \---------------- Network Interface Card or Serial Port -------------\ Card or Serial Port Cable Connection 5. System Requirements ======================= Socktalk requires a Windows-capable PC and the following: A) Microsoft Windows 3.x or Windows for Workgroups or Windows-NT B) Digitalk Smalltalk/V for Windows or Win32 C) A TCP/IP protocol stack with a Windows Sockets compliant DLL. A TCP/IP stack with a Windows Sockets DLL is included with Windows-NT. Other sources are:  Trumpet Winsock by Peter Tattam - Available through anonymous FTP from microdyne.com in directory /pub/winsock  Chameleon NetManage - Available from NetManage, Inc. D) A driver for your network interface card or equivalent driver (e.g. SLIP ...) Socktalk will run on multiple machines connected by a network or serial communications (if using SLIP), or on a single machine using the loopback entry (which is both the server and the client). Aug 17/94 Socktalk - LPC Consulting Services page 3 6. Source of Information on Windows Sockets and TCP/IP ====================================================== Book ---- Internetworking with TCP/IP Volume III: Client-Server Programming and Applications - Comer, D. and Stevens, D. Prentice Hall [1991] Windows Sockets Specification Version 1.1 ----------------------------------------- . Available on the Internet through anonymous FTP from microdyne.com in directory /pub/winsock . Available on CompuServe in the Microsoft Win32 SDK forum (GO MSWIN32) in a variety of formats (Postscript, ASCII, Windows help file, etc.). See library 12 - API-WinNet/RPC, and search by keyword SOCKETS. Windows Sockets Programming and TCP/IP Networking ------------------------------------------------- There are a number of files you can download from Compuserve in the Microsoft Win32 SDK MSWIN32 forum, library 12 - API- WinNet/RPC . Do a search by keywords SOCKETS or WINSOCK. The following Internet Newsgroups cover Windows Sockets and TCP/IP networking: . alt.winsock . alt.winsock.hackers . alt.winsock.users . comp.os.ms-windows.networking.tcp-ip Aug 17/94 Socktalk - LPC Consulting Services page 4 7. TECHNICAL SUMMARY ==================== Socktalk Class Hierarchy WinsockDLL WsStructure Hostent Linger Netent Protoent Servent Sockaddr WSAData WsObject InvalidEntry WsEntry HostEntry NetworkEntry ProtocolEntry ServiceEntry WsSocket WsClient TCPClient UDPClient WsServer TCPserver UDPserver WsTask WsAsyncHost WsAsyncProto WsAsyncServ Aug 17/94 Socktalk - LPC Consulting Services page 5 Socktalk Class Libraries WinsockDLL This class contains all the functions supplied by the Windows Sockets Dynamic Link Library (winsocks.dll). Since all the functionality provided by Windows Sockets has been encapsulated in other classes, all the methods in this class are private. WsStructure This is an abstract class which regroups all the structures required to interface to windows sockets. Access to these structures has been encapsulated in other classes, therefore all the methods in this class and its subclasses are private. Hostent This encapsulates the hostent (host) sockets structure Linger This encapsulates the structure to manipulate the linger option. Netent This encapsulates the netent (network) sockets structure Protoent This encapsulates the protoent (protocol) sockets structure Servent This encapsulates the servent (service) sockets structure Sockaddr This encapsulates the sockaddr_in (Socket address, internet style) sockets structure. WSAData This encapsulates the WSAData (information about the Windows Sockets implementation) structure. WsObject This is an abstract data class which regroups all the public classes of socktalk. The class method provide the following: . conversion (network to host format and vice-versa) . access to the Windows Sockets implementation information It also provides error handling and various global methods and constants. InvalidEntry This is the representation of an WsEntry which is invalid (i.e. the Ws Entry could not be created successfully). WsEntry This is an abstract class which regroups the various entries when interfacing to Socktalk (hosts, networks, protocols and services). Aug 17/94 Socktalk - LPC Consulting Services page 6 HostEntry This is the class representing hosts. NetworkEntry This is the class representing networks. ProtocolEntry This is the class representing protocols. ServiceEntry This is the class representing services WsSocket This class is an abstraction of a socket. It is an abstract class, and the subclasses of WsClient and WsServer should be used to write applications. It implements operations which are common to both client and server sockets. WsClient This class is an abstraction of a Windows Sockets client socket. It is an abstract class and the TCPClient or UDPClient class should be used to instantiate clients for the appropriate protocol. TCPClient This class implements stream (TCP) client sockets. UDPClient This class implements datagram (UDP) client sockets. WsServer This class is an abstraction of a Windows Sockets server socket. It is an abstract class and the TCPServer or UDPServer class should be used to instantiate servers for the appropriate protocol. TCPServer This class implements stream (TCP) server sockets. UDPServer This class implements datagram (UDP) server sockets. WsTask This is an abstract class which regroups the asynchronous Windows Sockets database queries. WsAsyncHost This class encapsulates the asynchronous host database queries (WSAAsyncGetHostByAddr, WSAAsyncGetHostByName) WsAsyncProto This class encapsulates the asynchronous protocol database queries (WSAAsyncGetProtoByName, WSAAsyncGetProtoByNumber) Aug 17/94 Socktalk - LPC Consulting Services page 7 WsAsyncServ This class encapsulates the asynchronous service database queries (WSAAsyncGetServByName, WSAAsyncGetServByPort Pool Dictionary WsConstants This dictionary contains the relevant values from the winsock.h windows sockets include file. Only the relevant constants from the file are included (e.g. unsupported protocols, address families are not in the dictionary). WsEvents This dictionary contains the values of the flags for the WSAAsyncSelect calls. These values are used for non-blocking (asynchronous) sockets programming. They correspond to the FD_READ, FD_WRITE ... values defined in the winsocks.h file. WsErrors This dictionary contains the error messages corresponding to Windows Sockets error numbers. WinEventsExtra This dictionary already exists in the Smalltalk image. Windows sockets defines 4 new message entries in it. If the message numbers are already being used by an application, the appropriate entries should be changed in this dictionary. The entries are as follows: WinEventsExtra at: 49236 put: #wmWsEvent:with: ; at: 49238 put: #wmWsGetHost:with: ; at: 49240 put: #wmWsGetProto:with: ; at: 49242 put: #wmWsGetServ:with: Aug 17/94 Socktalk - LPC Consulting Services page 8 8. Socktalk Programming Example =============================== The following classes (DaytimeServerVm andDaytimeTCP) demonstrate how Socktalk is used to develop a daytime asynchronous server in Smalltalk for Windows. Note that while the daytime server is running in a "live" image, the developer can still work in the Smalltalk image. Only the methods relevant to Socktalk are shown here: Start is invoked when the server is started. start "Callback for the menu item titled 'Start'. (Generated by WindowBuilder)" | returnCode aTextDisplay| connectionSockets := Dictionary new. aTextDisplay := self paneNamed: 'logDisplay'. " initialize the Windows Sockets library ..." returnCode := WsObject startup. WsObject hasError ifTrue: [ self handleError: WsObject. ^self close ]. " Display Windows Sockets DLL info ..." aTextDisplay nextPutAll: 'DLL Description: ' ; nextPutAll: WsObject description ; cr ;nextPutAll: 'System status: ' ; nextPutAll: WsObject systemStatus ; cr. aTextDisplay nextPutAll: 'Maximum Number of Sockets: ' ; nextPutAll: WsObject maxSockets asString ; cr. aTextDisplay nextPutAll: 'Size of largest UDP datagram: ' ; nextPutAll: WsObject maxUdpDg asString ; cr. " Start the daytime server ..." Daytime := DaytimeTCP start. Daytime hasError ifTrue: [ self handleError: Daytime. ^self close ]. Aug 17/94 Socktalk - LPC Consulting Services page 9 " make the socket asynchronous We will be notified when a client tries to connect " Daytime asyncSelect: self asParameter wMsg: 2047 lEvent: ( FdAccept ). Daytime hasError ifTrue: [ self handleError: Daytime. ^self close ]. ------------------------------- FdAccept is triggered by a windows message when a connection is made by a client. FdAccept: theAcceptingSocket errorCode: theErrorCode "accepts a client connection" | aTextDisplay aSocket | aTextDisplay := self paneNamed: 'logDisplay'. aTextDisplay cr ; nextPutAll: 'Received Accept event'; cr. " create a connected socket" self socketAccept. ------------------------------------ socketAccept creates a connection socket which will be used to send the date and time. socketAccept "comment" | aSocket | aSocket := Daytime accept. aSocket isInvalid ifTrue: [ self handleError: aSocket. ^nil ]. " we have the socket ... let 's establish notification ..." connectionSockets at: aSocket descriptor put: aSocket. aSocket asyncSelect: self asParameter wMsg: 2047 lEvent: ( FdWrite ). aSocket hasError ifTrue: [ self handleError: aSocket ]. ^aSocket ------------------------------ Aug 17/94 Socktalk - LPC Consulting Services page 10 FdWrite is triggered by a windows message when a socket is able to send data. FdWrite: theDescriptor errorCode: theErrorCode "ready to write on the connected socket" | aTextDisplay aSocket | aTextDisplay := self paneNamed: 'logDisplay'. aTextDisplay cr ; nextPutAll: 'Received Ready to write event'; cr. aSocket := connectionSockets at: theDescriptor. " send date and time ..." aSocket send: (Time dateAndTimeNow printString) flags: 0. aSocket hasError ifTrue: [ self handleError: aSocket ]. " finished with the socket " aSocket close. aSocket hasError ifTrue: [ self handleError: aSocket ]. " socket has been closed - remove it ... " connectionSockets removeKey: theDescriptor . --------------------------- Error handler for daytime server handleError: anObject "handles error" MessageBox message: ('*** Error - return code is: ', anObject getLastError asString)! ------------------------ Exit is invoked to stop the service exit "stops the server" Daytime close. Daytime hasError ifTrue: [ self handleError: Daytime. ^self close ]. Aug 17/94 Socktalk - LPC Consulting Services page 11 " tell he socket library to cleanup ..." WsObject cleanup. self close. --------------------------------------------------------------------------- This is the application class used to implement daytime !DaytimeTCP class methods ! port "returns the daytime service port" ^super port: self service! service " returns the service name" ^ 'daytime'! start "starts an Async TCP server" | theServer aConnectionSocket aTextWindow| theServer := self new. theServer hasError ifTrue: [ ^theServer ]. theServer onAddressAny. theServer hasError ifTrue: [ ^theServer ]. theServer listen. theServer hasError ifTrue: [ ^theServer ]. ^theServer! ! !DaytimeTCP methods ! ! *** none *** " Socktalk, the TCP/IP Communications Solution for Smalltalk/V ============================================================ Product Overview ---------------- LPC Consulting Services announces the availability of Socktalk, a Windows Socket compliant set of classes for Smalltalk/V for Windows and Win32 which interfaces to Windows Sockets (WinSock) compliant Dynamic Link libraries. It enables Smalltalk developers to deploy client server applications written entirely in Smalltalk. Socktalk supports both blocking (synchronous) and non-blocking (asynchronous) Windows Sockets applications. Note that while a Socktalk application is running in a "live" image, the developer can still continue work in the Smalltalk image. Socktalk comes with online help and sample programs which can be run against a remote server or a server session on a local machine. Full source code is included, and any executables developed using Socktalk can be distributed royalty-free. What is Windows Sockets ----------------------- Windows Sockets (WinSock) defines a Network Programming interface for Microsoft Windows based on the Berkeley Software Distribution (BSD) sockets. It is supported by a number of network software vendor and is included as part of Windows NT. System Requirements ------------------- Socktalk requires a Windows-capable PC and the following: 1. Microsoft Windows 3.x / Windows for Workgroups / Windows NT 3.1 2. Digitalk Smalltalk/V for Windows or Win32 3. A TCP/IP stack with a Windows Sockets DLL 4. A driver for your network interface card or equivalent driver (e.g. SLIP...)