MarshallSoft

Client / Server

Communications

Reference Library


(CSC_REF)


Version 4.0

March 28, 2007


This software is provided as-is.
There are no warranties, expressed or implied.



Copyright (C) 2007
All rights reserved



MarshallSoft Computing, Inc.
Post Office Box 4543
Huntsville AL 35815 USA


Voice : 1.256.881.4630

FAX : 1.256.880.0925

web : http://www.marshallsoft.com


MARSHALLSOFT is a registered trademark of MarshallSoft Computing.


TABLE OF CONTENTS

1 Introduction
1.1 General Remarks
1.2 Documentation Set
1.3 Declaration Files
1.4 Language Notes
2 CSC Functions
2.1 cscAcceptConnect
2.2 cscAttach
2.3 cscAwaitConnect
2.4 cscAwaitData
2.5 cscByteToShort
2.6 cscChallenge
2.7 cscClient
2.8 cscClose
2.9 cscConnectMessage
2.10 cscDataMessage
2.11 cscErrorText
2.12 cscGetData
2.13 cscGetFile
2.14 cscGetInteger
2.15 cscGetString
2.16 cscIsConnected
2.17 cscMakeDotted
2.18 cscPutData
2.19 cscPutFile
2.20 cscRelease
2.21 cscResolve
2.22 cscResponse
2.23 cscServer
2.24 cscSetInteger
2.25 cscSetString
2.26 cscShortToByte
2.27 cscSleep
2.28 cscSystemTics
3 CSC Error Return Code Lists

1 Introduction

The Client / Server Communications Library (CSC) is a Win32 component library of functions used to create server and client programs that can communicate with each other across any TCP/IP network such as the Internet or a private network (intranet or LAN [local area net]).

The CSC Reference Manual (CSC_REF) contains details on each individual CSC function.


1.1 General Remarks

All functions return an integer code. Negative values are always an error. See "CSC Error Codes" in Section 3. Non-negative return codes are never an error.

Note that the cscErrorText function is used to get the text message associated with any error code.

Each function argument is marked as:

Refer to the declaration files (see Section 1.3 below) for the exact syntax of each CSC function. Also note that the example programs show exactly how CSC functions are called.

For the latest version of the CSC software, see
http://www.marshallsoft.com/client-server-communication.htm


1.2 Documentation Set

The complete set of documentation consists of three manuals in three formats. This is the third manual (CSC_REF) in the set.

Each manual comes in three formats:

The CSC_4X Programmer's Manual is the language dependent manual and provides information needed to compile your programs as well as the examples in the specified environment. The "X" in CSC_4X specifies the host language such as "C" for C/C++/C++ .NET, "D" for Delphi, "VB" for Visual Basic, etc.

The CSC User's Manual (CSC_USR) discusses language independent programming issues. Information on Client/Server protocol as well as ordering information is also provided in the manual. Read this manual after reading the CSC_4x Programmer's Manual.

The CSC Reference Manual (CSC_REF) contains details on each individual CSC function..

Documentation is also provided online at
http://www.marshallsoft.com/client-server-communication.htm


1.3 Declaration Files

The exact syntax for calling CSC functions are specific to the host language (C/C++, Delphi, VB, etc.) and are defined for each language in the "CSC declaration files". Each Client/Server Communications Library product comes with the appropriate declaration file for the supported language. For example,

CSC4C   C/C++, C++ .NET          CSC.H
CSC4VB  Visual Basic             CSC16.BAS and CSC32.BAS
        VB.NET                   CSC32.VB
        VBA (EXCEL,ACCESS,etc.)  CSC32.BAS
CSC4D   Borland Delphi           CSC32.PAS

We also have declaration files (and some example programs) for PowerBASIC, Visual FoxPro, Visual dBase, Xbase++, and Fujitsu COBOL.


1.4 Language Notes

All language versions of CSC include the example program CSCVER. Refer to this program and the declaration file as defined in Section 1.3 above to see how CSC functions are called. The CSCVER program is also the first program that should be compiled and run.

The best way to see how a function is called is to find it used in one of the example programs. All CSC functions are used in one or more examples.

See "Using CSC with Supported Languages" in the CSC User's Manual (CSC_USR.DOC and CSC_USR.HTM)

1.4.1 C/C++/C#

Project files and/or makefiles supplied for the example programs. 32-bit Microsoft Visual C/C++, Visual C++ .NET, Borland C/C++, Borland C++ Builder, Watcom C/C++, Win32-LCC, and Visual C# are supported.

1.4.2 Delphi

Functions defined in the Delphi Unit CSCW.PAS begin with "f" rather than "csc".

All versions of 32-bit Delphi through Delphi 2005 are supported.

1.4.3 Visual Basic (and VB.NET)

All versions of 32-bit Visual Basic are supported through VB.NET.



2 CSC Functions


2.1 cscAcceptConnect :: Accept Connection from Client.

SYNTAX

cscAcceptConnect(vSock)

vSock : (I) Virtual (listener) socket number.

REMARKS

This function is used by the server to accept a connection from a client. cscAcceptConnect returns the (virtual) socket number that must be used in all subsequent calls to CSC functions that have a socket argument. Note that cscAcceptConnect can only be used in a server application.

EXAMPLE (C/C++ and VB)

Code = cscAcceptConnect(vSock)

vSock : (I) Virtual (listener) socket number.

RETURNS

< 0 : Error. See error list.
>= 0 : Virtual data socket.


2.2 cscAttach :: Initializes the CSC DLL.

SYNTAX

cscAttach(DataSocks, ListenSocks, KeyCode)

DataSocks : (I) Number of (data) virtual communications sockets.

ListenSocks : (I) Number of (listen) virtual communications sockets.

KeyCode : (I) Key code.

REMARKS

The cscAttach function must be the first CSC function called, and is used to pass the keycode (assigned when the library is registered) and the number of sockets to allow for both data and for listening for new connections.

For client applications, 'DataSocks' is the number of servers that the clients wants to connect to concurrently. This value is normally one. 'ListenSocks' is always zero for client applications.

For server applications, 'DataSocks' is the number of concurrent data connections (to clients) that are to be supported concurrently, and 'ListenSocks' is the number of different ports that a server wants to be able to accept connections to concurrently. This value is normally one.

EXAMPLE (C/C++ and VB)

// allow 1 data port and no listening ports, with keycode 0 Code = cscAttach(1, 0, 0)

RETURNS

< 0 : Error. See error list.
>= 0 : Days left in evaluation period (evaluation version only).


2.3 cscAwaitConnect :: Wait for Connection Attempt from Client.

SYNTAX

cscAwaitConnect(vSock, Timeout)

  vSock    : (I) Virtual (listen) socket number.
  Timeout  : (I) Timeout value in milliseconds.

REMARKS

This cscAwaitConnect function is used by a server program to wait a maximum specified time (in milliseconds) for a connection to be accepted from a client program.

EXAMPLE (C/C++)

if(cscAwaitConnect(ListenSock, 1000)) {// accept connection from client DataSock = cscAcceptConnect(ListenSock);

EXAMPLE (VB)

if cscAwaitConnect(ListenSock, 1000) <> 0 Then 'accept connection from client DataSock = cscAcceptConnect(ListenSock)

RETURNS

Returns TRUE : Client attempting to connect.

Returns FALSE : No connection attempt detected.



2.4 cscAwaitData :: Wait for Incoming Data.

SYNTAX

cscAwaitData(vSock, Timeout)

vSock : (I) Virtual (data) socket number.

Timeout : (I) Timeout value in milliseconds.

REMARKS

This cscAwaitData function is used to wait a specified time (in milliseconds) for incoming data from either a client or a server application.

This function should normally be called before calling cscGetData or cscGetFile.

EXAMPLE (C/C++)

char Buffer[128]; // wait (up to 2 seconds) for incoming data if(cscAwaitData(DataSock, 2000)) {// read data Code = cscGetData(DataSock, (char *)Buffer, 128);

EXAMPLE (VB)

Dim Buffer As String * 128 ' wait (up to 2 seconds) for incoming data if cscAwaitData(DataSock, 2000) <> 0 Then ' read data Code = cscGetData(DataSock, Buffer, 128)

RETURNS

Returns TRUE : Data is ready to be read.

Returns FALSE : No data is ready.



2.5 cscByteToShort :: Converts 8-bit Character Buffer to 16-bit

SYNTAX

cscByteToShort(Buffer)

Buffer : (P) character buffer

REMARKS

The cscByteToShort function converts the (null terminated) character buffer 'Buffer' from 8-bit ASCII characters to 16-bit Unicode ASCII characters.

The buffer must be null terminated (last character is a hex 00) and the buffer must be at least twice the size (in bytes) of the character string (since 16-bit characters require twice the space as 8-bit characters).

This function is only necessary when working with 16-bit Unicode ASCII characters in Visual C# and Delphi 2005.

RETURNS

None.

EXAMPLE (C#)

Refer to the Visual C# example ClientCS.csproj

   
     char[] UnsafeBuffer = new char[128];
     // get the registration string
     fixed (char* pBuffer = UnsafeBuffer)
     Code = cscGetString(-1, CSC_GET_REGISTRATION, pBuffer, 51);
     if(Code>0)
       {// convert (null terminated) UnsafeBuffer[] to 16-bit chars (unicode)
        fixed (char* pBuffer = UnsafeBuffer)
        cscByteToShort(pBuffer);
       }

ALSO SEE

cscShortToByte



2.6 cscChallenge :: Construct Challenge String

SYNTAX

cscChallenge(Buffer)

Buffer : (P) Buffer into which the challenge string is copied.

REMARKS

The cscChallenge function is used to construct a random 8-byte challenge string to be used to challenge the client before continuing with the connection.

The purpose of the cscChallenge and cscResponse functions is to create a challenge / response protocol in order to defeat hackers who may try to connect to your server.

Also see cscResponse, which computes the response to the challenge string.

EXAMPLE (C/C++)

char Challenge[9]; // challenge string // create random 8-digit number Code = cscChallenge((char *)Challenge);

EXAMPLE (VB)

Dim Challenge As String * 9 ' create random 8-digit number Code = cscChallenge(Challenge)

RETURNS

Returns the length of the challenge string, which is always 8.



2.7 cscClient :: Starts the Client.

SYNTAX

cscClient(ClientName, ClientPort)

ClientName : (P) Server name.

ClientPort : (I) Server port.

REMARKS

The cscClient is function is used to start the client which attempts to connect to the server and port specified. Note that the server must already be running before a connection can be established. cscClient returns the (virtual) socket number that must be used in all subsequent calls to CSC functions that have a socket argument. Note that cscClient can only be used in a client application.

EXAMPLE (C/C++)

char *HostName = "10.0.0.2"; short HostPort = 5001; int DataSock; // attempt to connect to server DataSock = cscClient((LPSTR)HostName, HostPort);

EXAMPLE (VB)

Dim HostName As String Dim HostPort As Integer Dim DataSock As Integer HostName = "10.0.0.2" HostPort = 5001 ' attempt to connect to server DataSock = cscClient(HostName, HostPort)

RETURNS

>= 0 : Virtual (data) socket number

else : Error (See error list)


2.8 cscClose :: Closes a Connection.

SYNTAX

cscClose(vSock)

vSock : (I) Virtual socket number.

REMARKS

The cscClose function closes a connection previously opened. Call this function only to close an open connection.

EXAMPLE (C/C++ and VB)

Code = cscClose(vSock)

RETURNS

< 0 : Error. See error list.
>= 0 : No error.


2.9 cscConnectMessage :: Sends Windows Message (on Connect).

SYNTAX

cscConnectMessage(Handle, vSock)

Handle : (I) Windows Handle

vSock : (I) Virtual listen socket.

Message : (I) Message (usually WM_USER)

REMARKS

The cscConnectMessage function sends a Windows message to the window with handle 'Handle' when a connection from a client is ready to be accepted.

Refer to the windows server example programs.

EXAMPLE (C/C++)

// Send WM_USER message when connection is ready to connect cscConnectMessage((long)hMainWnd, ListenSock, WM_USER);

EXAMPLE (VB)

Const WM_LBUTTONDOWN = &H201 ' send WM_LBUTTONDOWN message when connection is ready to connect Code = cscConnectMessage(Client.bReady.hWnd, ListenSock, WM_LBUTTONDOWN)

RETURNS

< 0 : Error. See error list.
>= 0 : No error.



2.10 cscDataMessage :: Sends Windows Message (on Data Ready).

SYNTAX

cscDataMessage(Handle, vSock)

Handle : (I) Windows Handle

vSock : (I) Virtual data socket.

Message : (I) Message (usually WM_USER)

REMARKS

The cscDataMessage function sends a Windows message to the window with handle 'Handle' when data is ready to be read from the other side (client or server).

Refer to the windows client example programs.

EXAMPLE (C/C++)

// Send WM_USER message when data is ready to be read cscDataMessage((long)hMainWnd, DataSock, WM_USER);

EXAMPLE (VB)

Const WM_LBUTTONDOWN = &H201 ' send WM_LBUTTONDOWN message when data is ready to be read Code = cscDataMessage(Client.bReady.hWnd, DataSock, WM_LBUTTONDOWN)

RETURNS

< 0 : Error. See error list.
>= 0 : No error.



2.11 cscErrorText :: Gets Text of Error Message.

SYNTAX

cscErrorText(ErrCode, Buffer, BufLen)

ErrCode : (I) Error code returned from a CSC function.

Buffer : (P) Buffer into which to copy text.

BufLen : (I) Length of above buffer.

REMARKS

The cscErrorText function is used to get the text of an error message associated with the error code returned from a CSC function.

Refer to the example programs.

EXAMPLE (C/C++)

char Buffer[128]; // get error text associated with error 'ErrCode' Code = cscError(ErrCode, (char *)Buffer, 128);

EXAMPLE (VB)

Dim Buffer As String * 128 ' get error text associated with error 'ErrCode' Code = cscError(ErrCode, Buffer, 128)

RETURNS

< 0 : Error. See error list.
>= 0 : Number of characters copied to Buffer.


2.12 cscGetData :: Receives Data from Established Connection.

SYNTAX

cscGetData(vSock, Buffer, BufLen)

vSock : (I) Virtual (data) socket.

Buffer : (P) Buffer into which to copy bytes.

BufLen : (I) Length of above buffer.

REMARKS

The cscGetData function is used to receive data from an established connection. All available data is copies to 'Buffer' up to a maximum of 'BufLen'. cscGetData never waits for data.

EXAMPLE (C/C++)

char Temp[128]; // read data (up to 128 bytes) Code = cscGetData(DataSock, (char *)Temp, 128);

EXAMPLE (VB)

Dim Temp As String * 128 ' read data (up to 128 bytes) Code = cscGetData(DataSock, Temp, 128)

RETURNS

< 0 : Error. See error list.
>= 0 : Number of bytes copied to Buffer.


2.13 cscGetFile :: Gets a File.

SYNTAX

cscGetFile(vSock, FileName)

vSock : (I) Virtual (data) socket number.

Filename : (P) Filename (not path) used to save incoming file or NULL.

REMARKS

The cscGetFile function is used to receive a file from an established connection transmitted from the cscPutFile function.

Specify the filename under which the file is to be saved, or specify an asterisk ("*") to save under the filename sent with the file. Then call cscGetFile repeatedly in a loop until 0 is returned.

The incoming data stream will contain the filename and the length of the file, followed by the (binary) file itself. The filename can be recovered by use of the cscGetString function and the file length can be recovered by use of the cscGetInteger function.

Also see cscSetString(-1, CSC_SET_FILE_PATH,...) to specify the file directory into which the file is to be saved.

EXAMPLE (C/C++)

// prepare to receive file, saving to disk Code = cscGetFile(DataSock, (char )""); // receive file in 4K blocks while(Code!=0) Code = cscGetFile(DataSock, NULL);

EXAMPLE (VB)

' prepare to receive file, saving to disk X = "*" + Chr(0) Code = cscGetFile(DataSock, X) // receive file in 4K blocks EmptyString = Chr(0) While Code <> 0 Code = cscGetFile(DataSock, EmptyString)

RETURNS

< 0 : Error. See error list.
>= 0 : No error.



2.14 cscGetInteger :: Returns CSC Numeric Parameter with Client/Server processing information.

SYNTAX

cscGetInteger(vSock, ParmName)

vSock : (I) Virtual socket number or -1.

ParmName : (I) Parameter name.

REMARKS

The cscGetInteger function is used to get integer parameters from the DLL.

CSC_GET_VERSION     : Get version number (vSock = -1)
CSC_GET_BUILD       : Get build number (vSock = -1)
CSC_GET_BUFFER_SIZE : Get file buffer size used by cscGetFile & cscPutFile.
CSC_GET_DAYS_LEFT   : Get the number days left in the evaluation period.
CSC_GET_SOCK_ERROR  : Get socket error number.
CSC_GET_SOCKET      : Get actual TCP/IP socket number being used.
CSC_GET_FILE_LENGTH : Get file length after receiving file (cscGetFile)

EXAMPLE (C/C++)

int Version; // get CSC version number Version = cscGetInteger(-1, CSC_GET_VERSION);

EXAMPLE (VB)

Dim Version As Integer ' get CSC version number Version = cscGetInteger(-1, CSC_GET_VERSION)

RETURNS

< 0 : Error. See error list.
>= 0 : Requested parameter.


2.15 cscGetString :: Returns CSC String Parameter with Client/Sever Processing Information.

SYNTAX

cscGetString(vSock, ParmName, Buffer, BufLen)

vSock : (I) Virtual socket number or -1.

ParmName : (I) Parameter name.

Buffer : (P) Buffer into which to copy text.

BufLen : (I) Length of above buffer.

REMARKS

The cscGetString function is used to get string (text) parameters from the DLL.

CSC_GET_REGISTRATION     : Get registration string.
CSC_GET_FILE_NAME        : Get filename after receiving file (cscGetFile).
CSC_GET_REMOTE_SERVER_IP : Get IP address in dotted notation of remote server.
CSC_GET_REMOTE_CLIENT_IP : Get IP address in dotted notation of remote client.
CSC_GET_LOCAL_IP         : Get local IP address in dotted notation.
CSC_GET_COMPUTER_NAME    : Get name of local computer.

EXAMPLE (C/C++)

// get registration string char RegString[128]; Code = cscGetString(vSock, CSC_GET_REGISTRATION, (char *)RegString, 128)

RETURNS

< 0 : Error. See error list.
>= 0 : Number of characters copied to Buffer.


2.16 cscIsConnected:: Returns the Current Connection Status.

SYNTAX

cscIsConnected(vSock)

vSock : (I) Virtual socket number.

REMARKS

The cscIsConnected function is used determine the current connection status.

Awaiting incoming socket data (cscAwaitData), reading socket data (cscGetData), and writing socket data (cscPutData) will all return an error code if the socket connection has been dropped.

EXAMPLE (C/C++)

//test connection if(!cscIsConnected(vSock)) {printf("*** ERROR: Connection has been dropped!\n"); break; }

EXAMPLE (VB)

Dim vSock As Long If cscIsConnected(vSock) <> 0 Then Result.Text = "*** ERROR: Connection has been dropped!" End If

RETURNS

True : Connective is OK.

False : Connection has been dropped.



2.17 cscMakeDotted :: Create IP Address in Dotted Notation.

SYNTAX

cscMakeDotted(Addr, Buffer, BufLen)

Addr : (L) 32-bit IP address.

Buffer : (P) Buffer into which to copy dotted address.

BufLen : (I) Length of above buffer.

REMARKS

The cscMakeDotted function is used to create a dotted text version of the specified IP address.

EXAMPLE (C/C++)

ULONG Addr; Addr = cscResolve((char *)"www.marshallsoft.com", 0); // construct dotted decimal equivalent string if(Addr) cscMakeDotted(Addr, (char *)Temp, 64);

EXAMPLE (VB)

Dim Addr As Long Dim X As String Dim Temp As String * 64 X = "www.marshallsoft.com" Addr = cscResolve(X, 0) ' construct dotted decimal equivalent string If Addr <> 0 Then cscMakeDotted(Addr, Temp, 64)

RETURNS

< 0 : Error. See error list.
>= 0 : IP address in dotted decimal notation (eg: "10.0.0.1")


2.18 cscPutData :: Transmits Data.

SYNTAX

cscPutData(vSock, Buffer, BufLen)

vSock : (I) Virtual (data) socket number.

Buffer : (P) Data to write.

BufLen : (I) Length of above buffer (# bytes to write).

REMARKS

The cscPutData function is used to write (transmit) a buffer to an established connection.

In general, limit the amount of data that is written in any one call to cscPutData since it is possible to overwhelm TCP/IP within Windows. In general, no more than 8KB should be written in one call to cscPutData.

EXAMPLE (C/C++)

char *Temp = "Hello"; // write 5 bytes of data Code = cscPutData(DataSock, (char *)Temp, 5);

EXAMPLE (VB)

Dim Temp As String Temp = "Hello" ' write 5 bytes of data Code = cscPutData(DataSock, Temp, 5)

RETURNS

< 0 : Error. See error list.
>= 0 : Number of bytes written.


2.19 cscPutFile :: Transmits File to Remote.

SYNTAX

cscPutFile (vSock, FileName)

vSock : (I) Virtual (data) socket number.

FileName : (P) Filename (not path) to transmit.

REMARKS

The cscPutFile function is used to transmit a file from an established connection transmitted to the cscGetFile function.

Call cscPutFile with a filename to specify the file to be sent, then call cscPutFile repeatedly in a loop until 0 is returned.

The outgoing data steam will contain the filename and the length of the file, followed by the (binary) file itself.

Also see cscSetString(-1, CSC_SET_FILE_PATH, ...) to specify the file directory from which the file will be read.

EXAMPLE (C/C++)

// prepare to transmit file "MyFile.zip" to the remote Code = cscPutFile(DataSock, (char *)"MyFile.zip"); // transmit file in 4K blocks while(Code!=0) Code = cscPutFile(DataSock, NULL);

EXAMPLE (VB)

Dim Filename As String Filename = "MyFile.zip" ' prepare to transmit file "MyFile.zip" to the remote Code = cscPutFile(DataSock, Filename) ' transmit file in 4K blocks EmptyString = Chr(0) While Code <> 0 Code = cscPutFile(DataSock, EmptyString)

RETURNS

< 0 : Error. See error list.
>= 0 : No error.



2.20 cscRelease :: Releases DLL.

SYNTAX

cscRelease()

REMARKS

The cscRelease function is used to release CSC32.DLL and should be the last CSC function called.

EXAMPLE (C/C++)

int Code; // release CSC32.DLL Code = cscRelease();

EXAMPLE (VB)

Dim Code As Integer ' release CSC32.DLL Code = cscRelease()

RETURNS

< 0 : Error. See error list.
>= 0 : No error.


2.21 cscResolve :: Resolves Host Name into IP Address.

SYNTAX

cscResolve(HostName, HostIndex)

HostName : (P) Server name or IP address (in dotted notation).

HostIndex : (I) Server index (if multi-homed).

REMARKS

The cscResolve function is used to resolve a host name to an IP address by calling DNS (Domain Name Services).

EXAMPLE (C/C++)

ULONG Addr; // resolve host name into an IP address. Addr = cscResolve((char *)"www.marshallsoft.com", 0);

EXAMPLE (VB)

Dim Addr As Long Dim URL As String URL = "www.marshallsoft.com" ' resolve host name into an IP address. Addr = cscResolve(URL, 0)

RETURNS

< 0 : Error. See error list.
>= 0 : IP address.


2.22 cscResponse :: Constructs Response String.

SYNTAX

cscResponse(ChallStr,Multi,Mask,Rotate,Response)

ChallStr : (P) 8 character challenge string (in hex)

Mult : (I) 32-bit multiplier

Mask : (I) 32-bit mask value

Rotate : (I) Left rotate count (0 to 31)

Response : (P) Buffer for response string

REMARKS

The cscResponse function constructs the correct response string for the given challenge string.

The purpose of the cscChallenge and cscResponse functions is to create a challenge / response protocol in order to defeat hackers who may try to connect to your server.

The arguments to the cscResponse function define the mapping from the 8-byte challenge string to the 8-byte response string. Each developer should choose unique values for his application.

Also see cscChallenge, which constructs the random challenge string.

EXAMPLE (C/C++)

char Challenge[9]; // challenge string char Response[9]; // response string ULONG Multiplier = 321; // 32-bit multiplier ULONG Mask = 0x1a2b3c4d; // 32-bit mask value int RotateCount = 3; // left rotate count (0 to 31) // compute correct response for the challenge number Code = cscResponse((char *)Challenge, Multiplier, Mask, RotateCount, (char *)Response);

EXAMPLE (VB)

Dim Challenge As String Dim Response As String * 9 Dim Multiplier As Integer Dim Mask As Long Dim RotateCount As Integer Multiplier = 321 Mask = &H1a2b3c4d RotateCount = 3 // compute correct response for the challenge number Code = cscResponse(Challenge, Multiplier, Mask, RotateCount, Response)

RETURNS

< 0 : Error. See error list.
>= 0 : No error.



2.23 cscServer :: Starts the Server.

SYNTAX

cscServer(ServerName, ServerPort, MaxConnect)

  ServerName : (P) Server name or IP address, or NULL.
  ServerPort : (I) Server port to listen on.
  MaxConnect : (I) Maximum number of connections to accept.

REMARKS

The cscServer function is used to accept a connection from a client. Up to 'MaxConnect' connections can be accepted by the server concurrently.

Specify the server name or IP address (in dotted decimal notation) and the port to listen on. Specify NULL or an empty string for ServerName if you want to accept connections on any IP on the local machine.

For server applications, be sure to allocate one listen socket for each port that is to be listened on concurrently.

EXAMPLE (C/C++)

HostName = "\0"; short HostPort = 5001; // start server, accepting a maximum of 1 connection Code = cscServer((char *)HostName, (int)HostPort, 1);

EXAMPLE (VB)

Dim HostName As String Dim HostPort As Integer HostName = Chr(0) HostPort = 5001 Code = cscServer(HostName, HostPort, 1)

RETURNS

>
0 : Listen socket.
< 0 : Error (See error list)



2.24 cscSetInteger :: Sets numeric parameter which contains client/server processing information.

SYNTAX

cscSetInteger(vSock, ParamName, ParamValue)

vSock : (I) Virtual socket number or -1.

ParmName : (I) Parameter name.

ParmValue : (I) Parameter value.

REMARKS

The cscSetInteger function is used to set an integer parameter in the DLL.

Parameter names are as follows:

CSC_SET_BLOCKING_MODE : Set blocking mode (during connect only). Default = TRUE

CSC_SET_BUFFER_SIZE   : Set write packet size. Default = 4096.
CSC_SET_SLEEP_TIME    : Set sleep time value when waiting. Default = 100.
CSC_SET_DEBUG_LEVEL   : Set debug level (0=off, 1=low, 2-high). Default = 0.
CSC_SET_LINGER        : Sets linger time when socket is closed. Default = 200
CSC_SET_TIMEOUT_VALUE : Set packet timeout. Default = 10000.

All time values are in milliseconds.

The blocking mode (1
block, 0 = don't block) applies only while connecting. The write buffer size can be changed from the default of 4096 to any value from 1024 to 4096. The sleep value is used in certain functions to introduce a time delay. The default debug level is 0 (off). The linger time is the delay after closing a socket to allow any ongoing communications to complete on the socket. The timeout-value is used by cscGetFile and specified how long to wait for individual fields before giving up.

EXAMPLE (C/C++)

int Code; // set 100 ms sleep time Code = cscSetInteger(vSock, CSC_SET_SLEEP_TIME, 100);

EXAMPLE (VB)

Dim Code As Integer ' set 100 ms sleep time Code = cscSetInteger(vSock, CSC_SET_SLEEP_TIME, 100)

RETURNS

< 0 : Error. See error list.
>= 0 : No error.


2.25 cscSetString :: Sets parameter string for file processing.

SYNTAX

cscSetString(vSock, ParmName, ParmPtr)

vSock : (I) Virtual socket number or -1.

ParmName : (I) Parameter value.

ParmPtr : (P) Parameter string to set.

REMARKS

The cscSetString function is used to pass string (text) parameters in the DLL.

Parameter names are as follows (pass vSock = -1).

CSC_SET_LOG_FILE : name of the log file.

CSC_WRITE_TO_LOG : write string to log file.

CSC_SET_FILE_PATH : sets path location for cscPutFile and cscGetFile.

EXAMPLE (C/C++)

int Code; // set LOG filename Code = cscSetString (-1, CSC_SET_LOG_FILE, (char *)"MY-PROGRAM.LOG");

EXAMPLE (VB)

Dim Code As Integer Dim LogName As String ' set LOG filename LogName = "MY-PROGRAM.LOG" Code = cscSetString (-1, CSC_SET_LOG_FILE, LogName)

RETURNS

< 0 : Error. See error list.
>= 0 : No error.


2.26 cscShortToByte :: Converts 16-bit ASCII character buffer to 8-bit

SYNTAX

cscShortToByte(Buffer)

Buffer : (P) character buffer

REMARKS

The cscShortToByte function converts the (null terminated) character buffer 'Buffer' from 16-bit Unicode ASCII characters to 8-bit ASCII characters.

The buffer must be null terminated (last character is a hex 00).

This function is only necessary when working with 16-bit Unicode ASCII characters in C# and Delphi 2005.

RETURNS

None.

EXAMPLE (C#)

See C# example ClientCS.csproj

   
     NameString = "MyFile.zip\0"
     char[] NameBuffer = NameString.ToCharArray();
     // convert (null terminated) 16-unicode buffer to 8-bit
     fixed (char* pNameBuffer = NameBuffer)
     cscShortToByte(pNameBuffer);
   

ALSO SEE

cscByteToShort



2.27 cscSleep :: Sleeps Specified Time.

SYNTAX

cscSleep(Milliseconds)

Milliseconds : (I) Number of milliseconds to sleep.

REMARKS

The cscSleep function sleeps for the indicated number of milliseconds. 'Milliseconds' must be positive.

This function is included in CSC because it is not available in all computer languages.

EXAMPLE (C/C++)

// sleep 1 second Tics = cscSleep(1000);

EXAMPLE (VB)

' sleep 1 second Tics = cscSleep(1000)

RETURNS

1 is always returned.


2.28 cscSystemTics :: Returns System Tics Count.

SYNTAX

cscSystemTics()

REMARKS

The cscSystemTics function returns the system tic count, which is the number of milliseconds since the system was booted.

The primary purpose of this function is to time various events.

This function is included in CSC because it is not available in all computer languages.

EXAMPLE (C/C++)

unsigned long Tics; // return current system tics Tics = cscSystemTics();

EXAMPLE (VB)

Dim Tics As Long ' return current system tics Tics = cscSystemTics()

RETURNS

The number of milliseconds since system bootup.



3 CSC Error Return Code List

The complete list of CSC error codes follows.


3.1 WINSOCK Error Codes

-10004: Interrupted system call.
-10009: Bad file number.
-10013: Access denied.
-10014: Bad address.
-10022: Invalid argument.
-10024: Too many open files.
-10035: Would block socket in non-blocking mode.
-10036: Blocking call already in progress.
-10037: Operation already completed.
-10038: Not a valid socket
-10039: Destination address required.
-10040: Message too big for buffer.
-10041: Prot mismatch.
-10042: Prot option invalid.
-10043: Prot not supported.
-10044: Socket type not supported.
-10045: Socket operation not supported.
-10047: Socket address family not supported.
-10048: Socket address already in use.
-10049: Socket address not available.
-10050: Network error.
-10051: Cannot reach network.
-10052: Connection dropped.
-10053: Connection timed-out or aborted.
-10054: Connection reset by remote host.
-10055: Out of buffer space.
-10056: Socket already connected.
-10057: Socket not connected.
-10058: Socket functionality shut down.
-10060: Timed-out attempting to connect.
-10061: Connection refused by remote host.
-10064: Host is down
-10065: No route to host
-10091: Network not yet ready.
-10092: WINSOCK doesn't support requested version.
-10093: Sockets not initialized. Call WSAStartup.
-11001: Host does not exist.
-11002: Host not found. Try again.
-11003: Non-recoverable error has occurred.
-11004: No data is available.


3.2 CSC Error Codes

-1: EOF.
-2: CSC aborted.
-3: CSC accept error.
-4: CSC already attached
-5: Cannot comply.
-6: No such socket.
-7: Connect error.
-8: Listen error.
-9: No such host.
-10: CSC not attached.
-11: NULL argument.
-12: NULL pointer.
-13: Cannot allocate memory
-14: Buffer size error
-15: Packet CRC error
-18: Too many sockets.
-19: File format protocol error.
-20: File name only.
-21: Packet timeout.
-22: Packet error.
-23: Transfer cancelled.
-24: File too large
-25: No listen socket
-26: Argument out of range
-74: Bad key code.


3.3 VSOCK Error Codes

-1001: No socket address.
-1002: No free sockets.
-1003: No such vsock.
-1004: Bad status flag.
-1005: Invalid socket.
-1006: No such parameter.
-1007: Cannot comply.
-1008: String size error.
-1009: No such server.
-1010: Buffer length error.
-1011: Connect error.