iASP_Sock Component

Overview

The iASP_Sock component exposes the WinSock API through a few simple properties and methods. It allows developers to build applications that connect to any TCP port and send or receive data.

Methods

To communicate the user needs to use the following five methods:

    • setRemoteHost().
    • setPort().
    • setTimeout().
    • Use any method accordingly.
    • Close().

Follow the following five steps to start communication (the following example is uses Visual Basic programming syntax).

        Set Socket = Server.CreateObject("ASPSock.Conn")
        Socket.setRemoteHost "halcyonsoft.com"

         

    • Set the RemotePort to a desired host by using 'setPort(int)' method.

      e.g.

    Socket.setPort 90

    • Call 'Open()' method to establish the connection.

      e.g.

        if (Socket.Open )
        Sock.Writeln "Connection is open"

    •  
      NOTE: setRemoteHost(String) property and setPort(int) property before calling 'Open()' method.

    • Set time by using 'setTimeout(int)' method. This method is used to set the the maximum time that iASP_Sock waits for a response from the Host. The user may set the time limit according to requirement.  60 seconds are already set by default.

      e.g.
               Socket.setTimeout(100)


      NOTE: Time is in seconds.

      See Appendix C for more details.

    • Now use any method after setting and getting the RemoteHost, Port, and Timeout.

      e.g.

      • Socket.Write "Well done Halcyon Soft Pvt Inc."
      • Socket WriteLn "Quitters Never Win and Winners Never Quit"
      • Socket ReadBytesAsString(40)
      • Socket ReadBytes(40)
      • Socket ReadLn


      See Appendix A for more details.

    • Call 'Close()' method of iASP_Socket class to disconnect.

      e.g.
            Socket.Close


    NOTE: Error occurs when the connection is not normally terminated.

Appendix A

Methods Description
public boolean Open()  It establishes a connection to the specified host and port and returns the connection state. 

Returns :

true:-  Connection established.
false:- Connection was not established.

public String setRemoteHost() It sets the name of that Host to which the connection is to be established.
 
public void getRemoteHost() It returns the Host name on which the connection is established.
public float getVersion() It returns the released version of the iASP_Sock component which is in use.
 
public void setPort(int portNumber) It sets the RemoteHost's Port. If the Port is not specified then the connection is established on Port '110'.

NOTE:- RemoteHost property must be set before the Port.
Note:- Set the TimeOut in milliseconds.

public int getPort() It returns the Port on which the connection is established with the RemoteHost.
public void setTimeout(int seconds) Timeout is the maximum time that iASP_Sock waits for a response, from the remote site. The default is 60 seconds.

NOTE: Set the Timeout in seconds.

public int getTimeout() It returns the Timeout.
public String Readln( ) IThis method takes no parameters and returns a String value, terminated with a <CRLF> i.e. Carriage Return Line Feed.
If no String value is returned from the RemoteHost up till Timeoutseconds, error is generated.
public Object ReadBytes(int readbytes) This method reads a ByteArray from the RemoteHost.

Paramter :
readbytes :- The maximum number of bytes to be read from the RemoteHost.

Returns :
Returns the ByteArray as an Object.

If no ByteArray is returned from the RemoteHost up till TimeOutseconds, error is generated.
 

public String ReadBytesAsString(int readbytes) This method reads a ByteArray from the RemoteHost.

Paramter :
readbytes :- The maximum number of bytes to  be read from the RemoteHost.

Returns :
Returns the ByteArray as a String.

If no ByteArray is returned from the RemoteHost up till Timeoutseconds, error is generated.

public boolean Write(String) Writes the specified string to the connection.
public boolean WriteLn(String) Writes the specified string to the connection terminated with a<CRLF>.
 
public void Close()  It closes the connection.

 

NOTE : Timeout is the maximum time that iASP_Sock waits for a response from the remote site. 
The default is 60 seconds.

Appendix B

Type  Variables Default Values 
public boolean  connected  false
public int Err  -1
public int port  none
public String  remoteHost  null
public int  timeout  60 seconds
public String  version  "1.0"

Appendix C

Errors Constants
ERROR_IN_SOCKET  0
CONNECTION_RESET  1
ERROR_IN_REINTIALIZATION  2
ERROR_IN_READING  3
HOST_NOT_FOUND  4
ERROR_IN_WRITING 5
HOST_NOT_DEFINE 6
NO_CONNECTION_ESTABLISHED  7
INVALID_BYTES_LENGTH 8

If you require technical support please send complete details about the problem you are having to support@halcyonsoft.com.


Copyright © 1998-2002, Halcyon Software Inc. All rights reserved.