TCP Server
ActiveX Control
Copyright 1995 - 1997 by Distinct Corporation.
All rights reserved.
Usage | Properties | Events | Methods | Header
The Distinct TCP Server ActiveX control allows you to build robust servers to serve multiple TCP clients on the network. It allows any workstation to act as a server; to listen for connection requests and process client queries. This ActiveX control takes care of converting internet addresses, binding sockets to a local port and accepting connection requests from a remote port. For ease of use all short and long integer values used (such as host addresses and ports) are specified in local host byte order. This frees you from converting arguments back and forth between function calls that require different byte orders for their arguments.
See the section entitled "Using Distinct ActiveX controls in various environments" on how to add the control to your project.
After placing a TCP Server ActiveX control into a form, some properties can be set at design time. If the ActiveX control will always listen on the same port, then the LocalPort property can be preset at design time. Since servers cannot use the default port value of 0, the LocalPort property must be set to a "well-known" port, which is known to the TCP clients that will send connection requests to the server.
Several properties control the way data is buffered during send and receive operations and how it is transferred to the application during a read operation. The SendSize and ReceiveSize properties specify the size of the send and receive buffers. Applications which will send large amounts of data can increase the size of the send buffer and applications which will receive large amounts of data can increase the size of the receive buffer. By increasing the send or receive buffer size, the ActiveX control may be able to increase throughput for some applications. The two buffer sizes are independent of each other.
The ReceiveLen property controls the maximum number of bytes of data which are read every time the receive buffer is accessed with the Receive property. The default value of 100 bytes should be sufficient for most applications. The SendTimeout property specifies the time-out value in seconds for sending data in the send buffer to the remote machine. The TCP Server ActiveX control will wait for the specified period of time (default is 20 seconds) to transmit the data in the send buffer. If the underlying protocol stack is unable to deliver the data within the given time, then the ActiveX control will time-out and return an error.
Properties which are set at design time can still be altered at run time.
The following properties can only be accessed at run time. The Action property is used to accept or close a connection and to listen for incoming connection requests. The HostConvert property converts host names to their corresponding internet addresses and vice versa. Since this operation may involve contacting a name server over the network, it can only be invoked at run time. The Receive and ReceiveCount properties are used to access data which has been received from the remote system over an established connection. The Send property sends data to the remote system over an established connection. The Result property contains the number of bytes sent to the remote machine or received from the remote machine. The value of this property can be checked after each send operation to ensure that all of the data was sent and after each receive operation to determine the number of bytes read from the receive buffer.
Connections for TCP servers are established by first setting the socket to listening mode. This is done by setting the Action property to ACTION_LISTEN (or by calling the Listen method). The LocalPort property must be initialized properly before listening because the default value of 0 cannot be used. Whenever a client sends a connection request over the network to the port on which the server is listening, an OnAccept event is fired for the TCP Server control. To establish a connection with the client, the Action property must be set to ACTION_ACCEPT (or call the Accept method) in response to this event. If the connection can be established, then the OnConnect event will occur before the next line of code is reached. Once a connection has been established, data can be sent with the Send property and available data can be received with the Receive property. Binary data can also be transferred using the ReceiveB and SendB methods.
The Option property can be used to set or reset specific socket options which change the behavior of the TCP Server ActiveX control. The Option property controls the actions taken when unsent data is queued in the send buffer when a connection is closed and specifies if the underlying protocol stack should use "keep-alive" packets on TCP connections. More details are given on the reference pages of the Option and OptionValue properties.
Out-of-band data is generally received separately from normal data. However, out-of-band data can also be received over the normal data stream by setting this socket option using the Option property. Out-of-band data can be sent and received using the SendOOB and ReceiveOOB properties. Arrival of out-of-band data will cause OnReceiveOOB events.
The Error property contains the error code returned by the underlying protocol stack if a socket operation could not be completed successfully. This value can be used to determine the exact nature of an error.
If a connection is no longer needed, then the Action property must be set to ACTION_DISCONNECT (or the Disconnect method must be called). Once the socket is closed, the OnDisconnect event will occur before the next line of code is reached. If no more connection requests will be accepted by the server on a listening socket, then the listening socket must be closed by setting the Action property to ACTION_CLOSE (or by calling the Close method). Once the listening socket is closed, the OnClose event will occur before the next line of code is reached. Applications must close any connected sockets and the listening socket in this way before terminating.
Action
Listen for, accept or close connections
Connection
Current socket connection
Convert
Convert protocol name to number and vice versa or service name
to service port and vice versa
Error
Error code returned by underlying protocol stack
HostAddress
Resolved internet address of host
HostConvert
Convert host name to address or address to host name or address
to dotted decimal
HostName
Name of host or dotted decimal internet address
Local
Name or dotted decimal internet address of local host
LocalPort
Local port to listen on
Option
Socket option
OptionValue
Socket option value
ProtocolName
Official protocol name
ProtocolNumber
Official protocol number
Receive
Receive buffer
ReceiveCount
Number of bytes waiting in receive buffer
ReceiveLen
Maximum number of bytes to read from receive buffer
ReceiveOOB
Receive buffer for out-of-band data
ReceiveSize
Size in bytes of receive buffer
RemotePort
Remote port used for connection
Result
Number of bytes sent or received
Send
Send buffer
SendOOB
Send buffer for out-of-band data
SendSize
Size in bytes of send buffer
SendTimeout
Timeout when sending data
ServiceName
Official service name
ServicePort
Port number on which service is available
OnAccept
Connection request has been received and is ready to be accepted
OnClose
Listening connection has been closed
OnConnect
Connection has been established
OnDisconnect
Connection has been closed
OnError
Local error has occurred
OnReceive
More data has been added to the receive buffer
OnReceiveOOB
More out-of-band data has been received
Accept
Accept a pending connection request
AddrToDecimal
Convert host address to dotted decimal address
AddrToName
Convert host address to host name
Close
Stop listening for incoming connection requests
Disconnect
Close accepted connection
KeepAlive
Send or not send keep-alive TCP packets
Linger
Set or not set linger time-out for close socket operation
Listen
Listen for incoming connection requests
NameToAddr
Convert host name to host address
ProtoNameToNumber
Convert protocol name to protocol number
ProtoNumberToName
Convert protocol number to protocol name
ReceiveB
Receive binary data
RecvOOB
Receive out of band data separately or as regular data
SendB
Send binary data
SvcNameToPort
Convert service name to service port
SvcPortToName
Convert service port to service name
The following provides a complete listing of the D_TCPSRV.TXT definition file. If your application uses more than one Distinct ActiveX control in the same form, then some definitions will conflict. For example, the FTP Client ActiveX control includes the definition
Global Const ACTION_DISCONNECT = 3
in the D_FTP.TXT file and the Telnet ActiveX control includes the definition
Global Const ACTION_DISCONNECT = 2
in the D_TNET.TXT file. To avoid this conflict, you must rename at least one of the constants (for example, FTP_ACTION_DISCONNECT or TNET_ACTION_DISCONNECT).
' TCP Server ActiveX Control
' (C) Copyright 1995 - 1997 by Distinct Corporation
' All rights reserved
' actions
Global Const ACTION_NONE = 0
Global Const ACTION_LISTEN = 1
Global Const ACTION_ACCEPT = 2
Global Const ACTION_DISCONNECT = 3
Global Const ACTION_CLOSE = 4
' address conversions
Global Const CONVERT_NONE = 0
Global Const CONVERT_ADDRESS_TO_NAME = 1
Global Const CONVERT_NAME_TO_ADDRESS = 2
Global Const CONVERT_ADDRESS_TO_DECIMAL = 3
' protocol and service conversions
' CONVERT_NONE is as defined above
Global Const PROTO_NAME_TO_NUMBER = 1
Global Const PROTO_NUMBER_TO_NAME = 2
Global Const SVC_NAME_TO_PORT = 3
Global Const SVC_PORT_TO_NAME = 4
' options
Global Const OPTION_NONE = 0
Global Const OPTION_LINGER_ON = 1
Global Const OPTION_LINGER_OFF = 2
Global Const OPTION_KEEPALIVE_ON = 3
Global Const OPTION_KEEPALIVE_OFF = 4
Global Const OPTION_RECV_OOB_ON = 5
Global Const OPTION_RECV_OOB_OFF = 6
' error codes
Global Const ERR_IN_ACTION = 1
Global Const ERR_CHANGE_LOCAL_PORT = 2
Global Const ERR_CHANGE_RECV_SIZE = 3
Global Const ERR_CHANGE_SEND_SIZE = 4
Global Const ERR_CANNOT_GET_SOCKET = 5
Global Const ERR_CANNOT_BIND_SOCKET = 6
Global Const ERR_CANNOT_SETUP_SOCKET = 7
Global Const ERR_CANNOT_LISTEN_SOCKET = 8
Global Const ERR_NOT_LISTENING = 9
Global Const ERR_CANNOT_ACCEPT = 10
Global Const ERR_CANNOT_RECV = 11
Global Const ERR_CANNOT_RECV_COUNT = 12
Global Const ERR_CANNOT_SEND = 13
Global Const ERR_NO_OPTION_VALUE = 14
Global Const ERR_CANNOT_GET_LOCAL = 15
Global Const ERR_CANNOT_RECV_OOB = 16
Global Const ERR_CANNOT_SEND_OOB = 17
' Windows Sockets error codes
Global Const WSABASEERR = 10000
Global Const WSAEINTR = (WSABASEERR+4)
Global Const WSAEBADF = (WSABASEERR+9)
Global Const WSAEACCES = (WSABASEERR+13)
Global Const WSAEFAULT = (WSABASEERR+14)
Global Const WSAEINVAL = (WSABASEERR+22)
Global Const WSAEMFILE = (WSABASEERR+24)
Global Const WSAEWOULDBLOCK = (WSABASEERR+35)
Global Const WSAEINPROGRESS = (WSABASEERR+36)
Global Const WSAEALREADY = (WSABASEERR+37)
Global Const WSAENOTSOCK = (WSABASEERR+38)
Global Const WSAEDESTADDRREQ = (WSABASEERR+39)
Global Const WSAEMSGSIZE = (WSABASEERR+40)
Global Const WSAEPROTOTYPE = (WSABASEERR+41)
Global Const WSAENOPROTOOPT = (WSABASEERR+42)
Global Const WSAEPROTONOSUPPORT = (WSABASEERR+43)
Global Const WSAESOCKTNOSUPPORT = (WSABASEERR+44)
Global Const WSAEOPNOTSUPP = (WSABASEERR+45)
Global Const WSAEPFNOSUPPORT = (WSABASEERR+46)
Global Const WSAEAFNOSUPPORT = (WSABASEERR+47)
Global Const WSAEADDRINUSE = (WSABASEERR+48)
Global Const WSAEADDRNOTAVAIL = (WSABASEERR+49)
Global Const WSAENETDOWN = (WSABASEERR+50)
Global Const WSAENETUNREACH = (WSABASEERR+51)
Global Const WSAENETRESET = (WSABASEERR+52)
Global Const WSAECONNABORTED = (WSABASEERR+53)
Global Const WSAECONNRESET = (WSABASEERR+54)
Global Const WSAENOBUFS = (WSABASEERR+55)
Global Const WSAEISCONN = (WSABASEERR+56)
Global Const WSAENOTCONN = (WSABASEERR+57)
Global Const WSAESHUTDOWN = (WSABASEERR+58)
Global Const WSAETOOMANYREFS = (WSABASEERR+59)
Global Const WSAETIMEDOUT = (WSABASEERR+60)
Global Const WSAECONNREFUSED = (WSABASEERR+61)
Global Const WSAELOOP = (WSABASEERR+62)
Global Const WSAENAMETOOLONG = (WSABASEERR+63)
Global Const WSAEHOSTDOWN = (WSABASEERR+64)
Global Const WSAEHOSTUNREACH = (WSABASEERR+65)
Global Const WSAENOTEMPTY = (WSABASEERR+66)
Global Const WSAEPROCLIM = (WSABASEERR+67)
Global Const WSAEUSERS = (WSABASEERR+68)
Global Const WSAEDQUOT = (WSABASEERR+69)
Global Const WSAESTALE = (WSABASEERR+70)
Global Const WSAEREMOTE = (WSABASEERR+71)
Global Const WSASYSNOTREADY = (WSABASEERR+91)
Global Const WSAVERNOTSUPPORTED = (WSABASEERR+92)
Global Const WSANOTINITIALISED = (WSABASEERR+93)
Global Const WSAHOST_NOT_FOUND = (WSABASEERR+1001)
Global Const WSATRY_AGAIN = (WSABASEERR+1002)
Global Const WSANO_RECOVERY = (WSABASEERR+1003)
Global Const WSANO_DATA = (WSABASEERR+1004)
Summary
Listen for, accept or close connections.
Description
The Action property controls the connection state of the TCP Server ActiveX control. The application can listen for incoming connection requests, accept requests or close established connections by assigning one of the following values to the property.
Value | Action |
ACTION_LISTEN | Listen for incoming connection requests. |
ACTION_ACCEPT | Accept a pending connection request. |
ACTION_DISCONNECT | Close accepted connection. |
ACTION_CLOSE | Stop listening for incoming connection requests. |
This property can be changed at run time only. There is no default value for this property.
The TCP Server ActiveX control can accept connections only when it is in listening mode. Before setting the Action property to ACTION_LISTEN, the LocalPort property must be set to the local port on which the server will be listening for connection requests. The default port cannot be used for TCP server sockets. Once the server is in listening mode, it can accept incoming connection requests. No event is generated in response to a successful ACTION_LISTEN action.
Whenever a client sends a connection request over the network to the port on which the server is listening, an OnAccept event is fired. In response to the OnAccept event, the application must set the Action property to ACTION_ACCEPT to establish a connection with the client.
If the connection can be established, then the OnConnect event will occur before the next line of code is reached. The OnConnect event will contain a socket connection handle which must be saved by the application. Since more than one client can connect to the server, the only way to identify an established connection is through this socket connection handle. Once a connection has been established, data can be sent with the Send property and available data can be received with the Receive property.
However, before sending or receiving data or closing a connection, the application must identify the connection on which this operation is to be performed. To identify the connection, the Connection property must be set to the socket connection handle obtained during the OnConnect event for the specific connection.
If a connection is no longer needed, then the Action property must be set to ACTION_DISCONNECT. Once the socket is closed, the OnDisconnect event will occur before the next line of code is reached. To identify which connection was closed, the socket connection handle is included in the OnDisconnect event.
If no more connection requests will be accepted by the server on a listening socket, then the listening socket must be closed by setting the Action property to ACTION_CLOSE. Once the listening socket is closed, the OnClose event will occur before the next line of code is reached.
The Listen, Accept, Disconnect and Close methods accomplish the same as the above actions. Please check the reference pages of these methods for more detailed information on their usage.
Applications must disconnect any accepted connections and close the listening socket before terminating.
Example
Server.LocalPort = 3000
Server.Action = ACTION_LISTEN
Summary
Current socket connection.
Description
The Connection property specifies the handle of the accepted connection on which further operations will be performed. This connection handle was delivered to the application during a previous OnConnect event. This property can be written to and read by the application at any time. If a socket operation does not succeed, then the Error property is set to the appropriate error code returned by the underlying protocol stack.
When the server accepts a new connection, an OnConnect event with the socket connection handle for the newly established connection is fired. The application must save this value so that it can set the Connection property to the appropriate handle to perform operations on the connection.
The application must set the Connection property to the value of the socket connection handle prior to any socket operations on that connection. All operations that follow will use the value of the Connection property as the current socket connection handle. The value of this property must be set before setting the Action property to ACTION_DISCONNECT, accessing the Receive property, accessing the ReceiveCount property, accessing the Send property or specifying a socket option using the Option property.
The value of the Connection property must be changed whenever the application wants to direct further socket operations to another connection. All operations will occur on the connection specified by the Connection property.
This property can be changed at any time. There is no default value for this property.
Example
Sub Server_OnReceive (Connection
As Integer)
Dim Message As String
Server.Connection = Connection
Message = Server.Receive
End Sub
Summary
Convert protocol name to number and vice versa or service name to service port and vice versa.
Description
The Convert property is used to convert a protocol name to a number and vice versa or a service name to a port and vice versa. The Convert property can be set to one of the following values.
Value | Conversion |
PROTO_NAME_TO_NUMBER | ProtocolName to ProtocolNumber. |
PROTO_NUMBER_TO_NAME | ProtocolNumber to ProtocolName. |
SVC_NAME_TO_PORT | ServiceName to ServicePort. |
SVC_PORT_TO_NAME | ServicePort to ServiceName. |
If Convert is set to PROTO_NAME_TO_NUMBER, then the control will convert the protocol name given by the ProtocolName property into the protocol number associated with the protocol name. The result of this lookup will be stored in the ProtocolNumber property. If the given protocol name cannot be resolved, then the ProtocolNumber property will be set to 0.
If Convert is set to PROTO_NUMBER_TO_NAME, then the control will convert the protocol number given by the ProtocolNumber property into the corresponding protocol name. The result of this lookup will be stored in the ProtocolName property. If the given protocol number cannot be resolved, then the ProtocolName property will be cleared.
If the Convert property is set to either SVC_NAME_TO_PORT or SVC_PORT_TO_NAME, then the name of the protocol to use when contacting the service must also be specified in the ProtocolName property.
If Convert is set to SVC_NAME_TO_PORT, then the control will convert the service name given by the ServiceName property (associated with the protocol specified by the ProtocolName property) into the service port where the service can be contacted. The result of this lookup will be stored in the ServicePort property. If the given service name cannot be resolved, then the ServicePort property will be set to 0.
If Convert is set to SVC_PORT_TO_NAME, then the control will convert the service port given by the ServicePort property (associated with the protocol specified by the ProtocolName property) into the corresponding service name. The result of this lookup will be stored in the ServiceName property. If the given service port cannot be resolved, then the ServiceName property will be cleared.
The Error property can be checked to obtain the error code returned by the underlying protocol stack.
The ProtoNameToNumber, ProtoNumberToName, SvcNameToPort and SvcPortToName methods accomplish the same as the above actions. Please check the reference pages of these methods for more detailed information on their usage.
This property can be changed at run time only. There is no default value for this property.
Example
Server.ProtocolName = "tcp"
Server.Convert = PROTO_NAME_TO_NUMBER
' Server.ProtocolNumber will now contain the protocol number for "tcp".
Server.ServiceName = "daytime"
Server.ProtocolName = "tcp"
Server.Convert = SVC_NAME_TO_PORT
' Server.ServicePort will now contain the port number of the "daytime"
service for "tcp" protocol.
Summary
Error code returned by underlying protocol stack.
Description
The Error property specifies the error code returned by the protocol stack if a socket operation could not be completed successfully. This property is read only.
The Error property reflects the error code of the last socket operation initiated by setting the Action, Option, Send, Convert or HostConvert properties (or by calling the equivalent method) or by accessing the Receive and ReceiveCount properties.
The value of this property must be checked immediately after initiating a socket operation. Accessing other properties may change the value of this property.
This property can be read at any time. There is no default value for this property.
The following is a list of possible error codes returned by the Windows Sockets protocol stack. Some of the error codes are not very common and hence are not listed here. Please check the documentation of the Windows Sockets for further information on these error codes.
Constant | Value | Meaning |
WSAEINTR | 10004 | Interrupted function call. |
WSAEACCES | 10013 | Permission denied. |
WSAEFAULT | 10014 | Bad address. |
WSAEINVAL | 10022 | Invalid argument. |
WSAEMFILE | 10024 | Too many open files |
WSAEWOULDBLOCK | 10035 | Resource temporarily unavailable. |
WSAEINPROGRESS | 10036 | Operation now in progress. |
WSAEALREADY | 10037 | Operation already in progress. |
WSAENOTSOCK | 10038 | Socket operation on non-socket. |
WSAEDESTADDRREQ | 10039 | Destination address required. |
WSAEMSGSIZE | 10040 | Message too long. |
WSAEPROTOTYPE | 10041 | Protocol wrong type for socket. |
WSAENOPROTOOPT | 10042 | Bad protocol option. |
WSAEPROTONOSUPPORT | 10043 | Protocol not supported. |
WSAESOCKTNOSUPPORT | 10044 | Socket type not supported. |
WSAEOPNOTSUPP | 10045 | Operation not supported. |
WSAEPFNOSUPPORT | 10046 | Protocol family not supported. |
WSAEAFNOSUPPORT | 10047 | Address family not supported by protocol family. |
WSAEADDRINUSE | 10048 | Address already in use. |
WSAEADDRNOTAVAIL | 10049 | Cannot assign requested address. |
WSAENETDOWN | 10050 | Network is down. |
WSAENETUNREACH | 10051 | Network is unreachable. |
WSAENETRESET | 10052 | Network dropped connection on reset. |
WSAECONNABORTED | 10053 | Software caused connection abort. |
WSAECONNRESET | 10054 | Connection reset by peer. |
WSAENOBUFS | 10055 | No buffer space available. |
WSAEISCONN | 10056 | Socket is already connected. |
WSAENOTCONN | 10057 | Socket is not connected. |
WSAESHUTDOWN | 10058 | Cannot send after socket shutdown. |
WSAETIMEDOUT | 10060 | Connection timed out. |
WSAECONNREFUSED | 10061 | Connection refused. |
WSAEHOSTDOWN | 10064 | Host is down. |
WSAEHOSTUNREACH | 10065 | No route to host. |
WSAEPROCLIM | 10066 | Too many processes. |
WSASYSNOTREADY | 10091 | Network subsystem is unavailable. |
WSAVERNOTSUPPORTED | 10092 | WINSOCK.DLL version out of range. |
WSANOTINITIALISED | 10093 | Successful WSAStartup() not yet performed. |
WSAHOST_NOT_FOUND | 11001 | Host not found. |
WSATRY_AGAIN | 11002 | Non-authoritative host not found. |
WSANO_RECOVERY | 11003 | This is a non-recoverable error. |
WSANO_DATA | 11004 | Valid name, no data record of requested type. |
The following describes each error in more detail.
WSAEINTR
A blocking operation was interrupted by a call to WSACancelBlockingCall().
WSAEACCES
An attempt was made to access a socket in a way forbidden by its access
permissions. An example is using a broadcast address for sendto() without
broadcast permission being set using setsockopt(SO_BROADCAST)
WSAEFAULT
The system detected an invalid pointer address in attempting to use
a pointer argument of a call. This occurs if an application passes an invalid
pointer value, or if the length of the buffer is too small. For instance,
if the length of a struct sockaddr is smaller than sizeof(struct sockaddr).
WSAEINVAL
Some invalid argument was supplied (for example, specifying an invalid
level to the setsockopt() function). In some instances, it also refers
to the current state of the socket - for instance, calling accept() on
a socket that is not listen()ing.
WSAEMFILE
Too many open sockets. Each implementation may have a maximum number
of socket handles available, either globally, per process or per thread.
WSAEWOULDBLOCK
This error is returned from operations on non-blocking sockets that
cannot be completed immediately, for example recv() when no data is queued
to be read from the socket. It is a non-fatal error, and the operation
should be retried later. It is normal for WSAEWOULDBLOCK to be reported
as the result from calling connect() on a non-blocking SOCK_STREAM socket,
since some time must elapse for the connection to be established.
WSAEINPROGRESS
A blocking operation is currently executing. Windows Sockets only allows
a single blocking operation to be outstanding per task (or thread), and
if you make any other function call (whether or not it references that
or any other socket) the function fails with the WSAEINPROGRESS error.
WSAEALREADY
An operation was attempted on a non-blocking socket that already had
an operation in progress - i.e. calling connect() a second time on a non-blocking
socket that is already connecting, or canceling an asynchronous request
(WSAAsyncGetXbyY()) that has already been canceled or completed.
WSAENOTSOCK
An operation was attempted on something that is not a socket. Either
the socket handle parameter did not reference a valid socket, or for select(),
a member of an fd_set was not valid.
WSAEDESTADDRREQ
A required address was omitted from an operation on a socket. For example,
if sendto() is called with the remote address as INADDR_ANY.
WSAEMSGSIZE
A message sent on a datagram socket was larger than the internal message
buffer or some other network limit, or the buffer used to receive a datagram
into was smaller than the datagram itself.
WSAEPROTOTYPE
A protocol was specified in the socket() function call that does not
support the semantics of the socket type requested. For example, you cannot
specify the ARPA Internet UDP protocol with a socket type of SOCK_STREAM.
WSAENOPROTOOPT
An unknown, invalid or unsupported option or level was specified in
a getsockopt() or setsockopt() call.
WSAEPROTONOSUPPORT
The requested protocol has not been configured into the system, or
no implementation for it exists. For example, a socket() call requests
a SOCK_DGRAM socket, but specifies a stream protocol.
WSAESOCKTNOSUPPORT
The support for the specified socket type does not exist in this address
family. For example, the optional type SOCK_RAW might be selected in a
socket() call, and the implementation does not support SOCK_RAW sockets
at all.
WSAEOPNOTSUPP
The attempted operation is not supported for the type of object referenced.
Usually, this occurs when a socket descriptor to a socket that cannot support
this operation, for example, trying to accept a connection on a datagram
socket.
WSAEPFNOSUPPORT
The protocol family has not been configured into the system or no implementation
for it exists. Has a slightly different meaning to WSAEAFNOSUPPORT, but
is interchangeable in most cases, and all Windows Sockets functions that
return one of these specify WSAEAFNOSUPPORT.
WSAEAFNOSUPPORT
An address incompatible with the requested protocol was used. All sockets
are created with an associated "address family" (i.e. AF_INET
for Internet Protocols) and a generic protocol type (i.e. SOCK_STREAM).
This error will be returned if an incorrect protocol is explicitly requested
in the socket() call, or if an address of the wrong family is used for
a socket, e.g. in sendto().
WSAEADDRINUSE
Only one usage of each socket address (protocol/IP address/port) is
normally permitted. This occurs if an application attempts to bind() a
socket to an IP address/port that has already been used for an existing
socket, or a socket that wasn't closed properly, or one that is still in
the process of closing. For server applications that need to bind() multiple
sockets to the same port number, consider using setsockopt(SO_REUSEADDR).
Client applications usually need not call bind() at all - connect() will
choose an unused port automatically.
WSAEADDRNOTAVAIL
The requested address is not valid in its context. Normally, results
from an attempt to bind() to an address that is not valid for the local
machine, or connect()/sendto() an address or port that is not valid for
a remote machine (e.g. port 0).
WSAENETDOWN
A socket operation encountered a dead network. This could indicate
a serious failure of your network system (i.e. the protocol stack that
the WINSOCK DLL runs over), the network interface, or the local network
itself.
WSAENETUNREACH
A socket operation was attempted to an unreachable network. This usually
means the local software knows no route to reach the remote host.
WSAENETRESET
The host you were connected to crashed and rebooted. May also be returned
by setsockopt() if you try to set SO_KEEPALIVE on a connection that has
already failed.
WSAECONNABORTED
An established connection was aborted by the software in your host
machine, possibly due to a data transmission timeout or protocol error.
WSAECONNRESET
A existing connection was forcibly closed by the remote host. This
normally results if the peer application on the remote host is suddenly
stopped, the host is rebooted, or the remote host used a "hard close"
(see setsockopt(SO_LINGER)) on the remote socket.
WSAENOBUFS
An operation on a socket could not be performed because the system
lacked sufficient buffer space or because a queue was full.
WSAEISCONN
A connect request was made on an already connected socket. Some implementations
also return this error if sendto() is called on a connected SOCK_DGRAM
socket (For SOCK_STREAM sockets, the to parameter in sendto() is ignored),
although other implementations treat this as a legal occurrence.
WSAENOTCONN
A request to send or receive data was disallowed because the socket
is not connected and (when sending on a datagram socket using sendto())
no address was supplied. Any other type of operation might also return
this error - for example, setsockopt() setting SO_KEEPALIVE if the connection
has been reset.
WSAESHUTDOWN
A request to send or receive data was disallowed because the socket
had already been shut down in that direction with a previous shutdown()
call. By calling shutdown(), you do a partial close of a socket, which
means you have discontinued sending or receiving or both.
WSAETIMEDOUT
A connection attempt failed because the connected party did not properly
respond after a period of time.
WSAECONNREFUSED
No connection could be made because the target machine actively refused
it. This usually results from trying to connect to a service that is inactive
on the foreign host - there is no server application running.
WSAEHOSTDOWN
A socket operation failed because the destination host was down. A
socket operation encountered a dead host. Networking activity on the local
host has not been initiated. These conditions are more likely to be indicated
by the error WSAETIMEDOUT.
WSAEHOSTUNREACH
A socket operation was attempted to an unreachable host. See WSAENETUNREACH
WSAEPROCLIM
A Windows Sockets implementation may have a limit on the number of
applications that may use it simultaneously. WSAStartup() may fail with
this error if the limit has been reached.
WSASYSNOTREADY
This error is returned by WSAStartup() if the Windows Sockets implementation
cannot function at this time because the underlying system it uses to provide
network services is currently unavailable. Users should check:
* that the WINSOCK.DLL file is in the current path,
* that the WINSOCK.DLL file is from the same vendor as your underlying protocol stack. You cannot mix and match (WINSOCK DLLs must be supplied by the same vendor that provided your underlying protocol stack).
* that you are not trying to use more than one WinSock implementation simultaneously. If you have more than one WINSOCK DLL on your system, be sure the first one in the path is appropriate for the network subsystem currently loaded.
* your WinSock implementation documentation to be sure all necessary components are currently installed and configured correctly.
WSAVERNOTSUPPORTED
The current WinSock implementation does not support the Windows Sockets
specification version requested by the application. Check that no old WINSOCK.DLL
files are being accessed, or contact your vendor to see if an updated WINSOCK.DLL
exists.
WSANOTINITIALISED
Either your application hasn�t called WSAStartup(), or WSAStartup()
failed. You may be accessing a socket which the current active task does
not own (i.e. you�re trying to share a socket between tasks), or you may
have already called WSACleanup() too many times.
WSAHOST_NOT_FOUND
No such host is known. The name you have used is not an official hostname
or alias, or it cannot be found in the database(s) being queried. This
error may also be returned for protocol and service queries, and means
the specified name could not be found in the relevant database.
WSATRY_AGAIN
This is usually a temporary error during hostname resolution and means
that the local server did not receive a response from an authoritative
server. A retry at some time later may be successful.
WSANO_RECOVERY
This indicates some sort of non-recoverable error occurred during a
database lookup. This may be because the database files (e.g. BSD-compatible
HOSTS, SERVICES or PROTOCOLS files) could not be found, or a DNS request
was returned by the server with a severe error.
WSANO_DATA
The requested name is valid and was found in the database, but it does
not have the correct associated data being resolved for. The usual example
for this is a hostname -> address translation attempt (using gethostbyname()
or WSAAsyncGetHostByName()) which uses the DNS (Domain Name Server), and
an MX record is returned but no A record - indicating the host itself exists,
but is not directly reachable.
Example
Const WSAENOTCONN = 10057
Server.Send = "test"
If Server.Error = WSAENOTCONN Then
MsgBox "Connection closed", 64, "Sample Program"
End If
Summary
Resolved internet address of host.
Description
The HostAddress property specifies the internet address of the remote machine. This property cannot be modified directly. Each time a connection is established, this property will be set to the address of the remote machine.
The HostAddress property is specified as a binary long address and not as a dotted decimal IP address.
To obtain the dotted decimal IP address given a host name, the application must first convert the host name specified by the HostName property into an internet address and then convert the internet address contained in the HostAddress property into an IP address in dotted decimal notation.
The TCP server does not know the address of the remote machine until the connection has been established. The HostAddress will contain the internet address of the remote machine once the connection is established. The HostConvert property can be used to convert the internet address to a host name or dotted decimal address. The application can check the HostName to determine if it should refuse connection and disconnect.
The value of the HostAddress property contains the internet address of the last established connection and hence should be verified immediately after the connection is established (inside the OnConnect event). It will change with each session that is established with the TCP server specifying the internet address for the most recently established connection. The application should save the HostAddress value along with the socket connection handle returned by the OnConnect event and the RemotePort property for each established connection. This information could be used to uniquely identify a connection.
The HostAddress property can be used independent of the Action property to convert between host addresses and host names for informational purposes. Since resolving a host name or address may involve sending queries over the network to a name server, the HostConvert property can only be used at run time. The HostAddress is a read-only property and cannot be set by the application.
Example
Server.HostName = "speedy.distinct.com"
Server.HostConvert = CONVERT_NAME_TO_ADDRESS
If Server.HostAddress = 0 Then
MsgBox "Unable to resolve host name ", 64, "Sample Program"
End If
Summary
Convert host name to address or address to host name or address to dotted decimal.
Description
The HostConvert property is used to convert a host name to a host address and vice versa and can be set to one of the following values.
Value | Conversion |
CONVERT_NAME_TO_ADDRESS | HostName to HostAddress. |
CONVERT_ADDRESS_TO_NAME | HostAddress to HostName. |
CONVERT_ADDRESS_TO_DECIMAL | HostAddress to dotted decimal HostName. |
If HostConvert is set to CONVERT_NAME_TO_ADDRESS, then the control will convert the host name (or the host address specified in dotted decimal notation) given with the HostName property into the internet address of the host. The result of this lookup will be stored in the HostAddress property. If the given host name cannot be resolved, then the HostAddress property will be set to 0.
If HostName contains an address in dotted decimal notation (for example, 127.43.101.12), then the control will simply convert the string to an internet address. Otherwise, the control first checks if the specified host is defined in the local host's database. If the host is not found, then the control will send queries over the network to a name server.
If HostConvert is set to CONVERT_ADDRESS_TO_NAME, then the control will convert the internet address given with the HostAddress property into the name of the host. The result of this lookup will be stored in the HostName property. If the given host address cannot be resolved, then the HostName property will be cleared.
The control first checks if the specified internet address is defined in the local host's database. If the address is not found, then the control will send queries over the network to a name server.
If HostConvert is set to CONVERT_ADDRESS_TO_DECIMAL, then the control will convert the internet address given with the HostAddress property into the dotted decimal address of the host. The result of this lookup will be stored in the HostName property. If the given host address is 0, then the HostName property will be cleared.
The NameToAddr, AddrToName and AddrToDecimal methods accomplish the same as the above actions. Please check the reference pages of these methods for more detailed information on their usage.
This property can be changed at run time only. There is no default value for this property.
Example
Server.HostName = "speedy"
Server.HostConvert = CONVERT_NAME_TO_ADDRESS
' Server.HostAddress will now contain the internet address in binary
long format.
Summary
Name of host or dotted decimal internet address.
Description
The HostName property specifies the name or internet address of a remote machine. Once a connection is established, the HostAddress property will be set to the internet address of the remote machine. The HostAddress property can be converted into a name or dotted decimal address using the HostConvert property.
The application can also set this property and use the HostConvert property to obtain the internet address of a remote machine. There are three possible ways of specifying a host name.
Machine Name
An application only needs to specify the name of the remote machine if the host is located on the same network as the local PC or if the internet address of the host is defined in the local hosts data base. If the remote machine is not on the local network, then the underlying protocol will route the traffic through a gateway. If the host is not defined in the local hosts data base, then the underlying protocol will contact the name server to resolve the internet address of the remote machine.
Machine and Domain Name
An application needs to specify the machine name and the domain name if the host is not located on the same network as the local PC. Fully domain qualified machine names are written from left to right in ascending order (for example, speedy.distinct.com). If both machine and domain names are specified, then the underlying protocol will contact the name server to resolve the internet address of the remote machine.
Internet Address
Sometimes the user knows only the internet address of the remote machine that he or she wants to use. In this case, the internet address can be entered in what is known as the dotted decimal notation (for example, 127.43.101.12). If the host identified by this address is not on the local network, then the underlying protocol will route the traffic through a gateway.
This property can be changed at design time and at run time before a connection has been established.
There is no default value for this property.
Example
Server.HostName = "127.43.101.12"
Server.HostConvert = CONVERT_NAME_TO_ADDRESS
' Server.HostAddress will now contain the internet address in binary
long format.
Summary
Name or dotted decimal internet address of local host.
Description
The Local property specifies the name or internet address of the local machine. This property can only be accessed during run time and can not be changed by the application.
Depending on the underlying protocol stack and how it is configured, the Local property may contain a simple host name or a fully qualified domain name.
To obtain the internet address of the local machine, the host name (or the local dotted decimal internet address) in the Local property can be assigned to the HostName property. Then, the HostConvert property can be used to obtain the corresponding internet address.
There is no default value for this property.
Example
Dim LocalHost As String
LocalHost = Server.Local
Summary
Local port to listen on.
Description
The LocalPort property is used to specify the local port on which the TCP server socket is listening. This port number is the value by which the server socket is known to other hosts. Remote machines connect and send messages to the local port of a socket. This property must be set before setting the Action property to ACTION_LISTEN (or before calling the Listen method).
The LocalPort property of the TCP Server ActiveX control defaults to 0. This default value can not be used by a server TCP socket. Since the remote machine must know to which port connection requests should be sent, the local port on which the server TCP socket is listening must be "well-known", that is, the port must be agreed upon by both machines.
This property can be set at design time and changed at any time before the socket is put into listening mode by setting the Action property to ACTION_LISTEN (or by calling the Listen method). The default value of this property is 0.
Example
Server.LocalPort = 3000
Server.Action = ACTION_LISTEN
Summary
Socket option.
Description
The Option property is used to specify the socket options associated with the TCP Server ActiveX control. The Option property can be set to one of the following values.
Value | Meaning |
OPTION_LINGER_ON* | Set linger time-out for close socket operation. |
OPTION_LINGER_OFF | Do not linger during close socket operation. |
OPTION_KEEPALIVE_ON | Send keep-alive TCP packets. |
OPTION_KEEPALIVE_OFF* | Do not send keep-alive TCP packets. |
OPTION_RECV_OOB_ON | Receive out-of-band data separately. |
OPTION_RECV_OOB_OFF* | Receive out-of-band data as regular data. |
* Default values
An application may request the underlying protocol stack to enable the use of keep-alive packets on TCP connections (provided the protocol stack supports the use of keep-alives) by setting the Option property to OPTION_KEEPALIVE_ON. The send and time-out intervals must be specified as required by the protocol stack in use. To disable keep-alive probes, set the Option property to OPTION_KEEPALIVE_OFF (this is the default setting).
The OPTION_LINGER_ON and OPTION_LINGER_OFF options control the behavior of the socket while disconnecting. If the Option property is set to OPTION_LINGER_ON, then the socket is not closed until all data buffered in the send buffer is transmitted or the given time-out has been exceeded. The time-out value in seconds must be specified with the OptionValue property. If OptionValue is set to 0 with linger enabled, then the connection will be reset. If the Option property is set to OPTION_LINGER_OFF, then the underlying protocol stack will close without waiting for buffered data to be sent. The TCP Server ActiveX control by default enables linger with a three second time-out.
Out-of-band data (or TCP urgent data) can be delivered to the user either separately from regular data or as part of regular data. If an application needs to process out-of-band data apart from regular data, then the Option property must be set to OPTION_RECV_OOB_ON. In this case, the arrival of out-of-band data will trigger the OnReceiveOOB event. The ReceiveOOB property can then be used to access the out-of-band data. By default, the OPTION_RECV_OOB_OFF setting is enabled and out-of-band data is received as part of the regular data stream.
The application must set the Connection property to the correct socket connection handle (obtained during the OnConnect event for the specific connection) before setting the Option property.
The Linger, KeepAlive and RecvOOB methods accomplish the same as the above actions. Please check the reference pages of these methods for more detailed information on their usage.
The Option property can be changed at any time before or after a connection is established. There is no default value for this property.
Example
Server.Option = OPTION_KEEPALIVE_ON
Summary
Socket option value.
Description
The OptionValue property is used to specify the value for options set using the Option property. Most options do not require a value but are simply enabled or disabled. However, to turn linger on, an application must specify the linger time-out in seconds in the OptionValue property.
Before setting the Option property to OPTION_LINGER_ON, the OptionValue property must be set to the value of the desired time-out in seconds. This will direct the underlying protocol stack how long to wait for data in the send buffer to be sent before closing the connection during ACTION_DISCONNECT. If the OptionValue property is set to 0 with linger enabled, then the connection will be reset during ACTION_DISCONNECT. The TCP Server ActiveX control by default enables linger with a three second time-out.
This property can be changed at any time before a connection is accepted (by setting the Action property to ACTION_ACCEPT) or the socket is put into listening mode (by setting the Action property to ACTION_LISTEN) and before the connection is closed (by setting the Action property to ACTION_DISCONNECT). There is no default value of this property.
Example
Server.OptionValue = 0
Server.Option = OPTION_LINGER_ON
Server.Action = ACTION_DISCONNECT ' connection reset
Summary
Official protocol name.
Description
The ProtocolName property specifies the official name of a protocol. This property is used to look up the corresponding protocol number or to look up a service name or number over the given protocol. This property must be set before setting the Convert property to PROTO_NAME_TO_NUMBER, SVC_NAME_TO_PORT or SVC_PORT_TO_NAME.
The TCP Server ActiveX control can look up either the protocol name given the number or the protocol number given the name. To convert the protocol name to the number, set the ProtocolName property to the name of the protocol and then set the Convert property to PROTO_NAME_TO_NUMBER. To retrieve the protocol name, set the ProtocolNumber property to the number of the protocol and then set the Convert property to PROTO_NUMBER_TO_NAME.
This property can only be changed at run time. There is no default value for this property.
Example
Server.ProtocolName = "tcp"
Server.Convert = PROTO_NAME_TO_NUMBER
' Server.ProtocolNumber will now contain the protocol number for "tcp".
Summary
Official protocol number.
Description
The ProtocolNumber property specifies the number of the protocol to be used while contacting a service. The protocol number and the protocol name are used to identify the protocol. This property must be set before setting the Convert property to PROTO_NUMBER_TO_NAME.
The TCP Server ActiveX control can look up either the protocol name given the number or the protocol number given the name. To convert the protocol name to the number, set the ProtocolName property to the name of the protocol and then set the Convert property to PROTO_NAME_TO_NUMBER. To retrieve the protocol name, set the ProtocolNumber property to the number of the protocol and then set the Convert property to PROTO_NUMBER_TO_NAME.
This property can only be changed at run time. There is no default value for this property.
Example
Server.ProtocolNumber = 0
Server.Convert = PROTO_NUMBER_TO_NAME
' Server.ProtocolName will now contain "tcp".
Summary
Receive buffer.
Description
The Receive property is used to access data that has been sent by the remote machine. This property can only be accessed by assigning its value to another string while a connection is established. Whenever the property is assigned to a string, as many bytes of data as possible up to the number specified by the ReceiveLen property are copied from the receive buffer into that string.
Usually, this property is read during an OnReceive event. This event informs the application that more data has arrived from the connected machine and also delivers the socket connection handle. At this point, the application should read all the data available and process it. Before assigning the receive buffer to a string, the application must set the Connection property to the socket connection handle specified in the OnReceive event. This tells the ActiveX control from which socket connection the application wants to read data. Once the Connection property is set correctly, the ReceiveCount property can be used to find out how many bytes of data are waiting in the receive buffer of that particular connection.
If the ReceiveLen property is set to a value less than the ReceiveCount property, then the application may have to read the Receive property more than once to read all available data. In general, the application should get data from the receive buffer until no more data is available. This condition can be detected by checking the length of the string to which the Receive property is assigned. As soon as this length is zero, all data has been read.
Since the ReceiveLen property can be changed at any time (even while connected), an application could assign the value of the ReceiveCount property to ReceiveLen. Any subsequent assignment of the Receive property would then copy all available data from the receive buffer into the application's buffer. This approach is not advisable if very large amounts of data are being received.
The Result property will contain the total number of bytes read from the receive buffer. The Result property will contain a value less than or equal to the value specified by the ReceiveLen property.
This property can only be read at run time while a connection is established. There is no default value for this property.
Example
Sub Server_OnReceive (Connection
As Integer)
Dim Message As String
Server.Connection = Connection
Message = Server.Receive
End Sub
Summary
Number of bytes waiting in receive buffer.
Description
The ReceiveCount property specifies how many bytes of data are available in the receive buffer. This property is read only and can only be accessed while a connection is established.
Before accessing the ReceiveCount property, the application must set the Connection property to the socket connection handle delivered during the OnConnect event for that specific connection. The ReceiveCount property will then retrieve the number of bytes of data that are available in the receive buffer of that socket connection.
Because of the interrupt driven nature of network communications, the value of the ReceiveCount property can change quickly at any time. An application should not rely on this value for an extended period of time without rechecking it.
The receive buffer can be accessed with the Receive property. The number of bytes read from the receive buffer while accessing the Receive property can be set with the ReceiveLen property.
This property can only be read at run time while a connection is established. There is no default value for this property.
Example
Sub Server_OnConnect (Connection
As Integer)
Server.Connection = Connection
If Server.ReceiveCount > 0 Then
MsgBox "Data is now available in the Receive buffer",
64, "Sample Program"
End If
End Sub
Summary
Maximum number of bytes to read from receive buffer.
Description
The ReceiveLen property determines the maximum number of bytes of data that are read from the receive buffer when an application accesses the Receive property.
The default value of 100 should be suitable for most applications, but any value other than zero is legal. Setting the ReceiveLen property value to one will cause the application to read one byte of data at a time. If an application wants to make sure that it reads the total number of bytes available, then it should set the value of the ReceiveLen property equal to the value of the ReceiveCount property before accessing the Receive property.
The receive buffer can be accessed with the Receive property. The total number of bytes waiting in the receive buffer can be determined by checking the ReceiveCount property.
This property can be changed at any time. The default value for this property is 100 bytes.
Example
Server.ReceiveLen = 25
Summary
Receive buffer for out-of-band data.
Description
The ReceiveOOB property is used to access any out-of-band data that has been sent by the remote machine. This property can only be accessed by assigning its value to another string while a connection is established. Whenever the property is assigned to a string, as many bytes of out-of-band data as possible up to the number specified by the ReceiveLen property are copied from the out-of-band receive buffer into that string.
Usually, this property is read during an OnReceiveOOB event. This event informs the application that more out-of-band data has arrived from the connected host and also delivers the socket connection handle. At this point, the application should read all available out-of-band data and process it. Before assigning the receive buffer to a string, the application must set the Connection property to the socket connection handle specified in the OnReceive event. This tells the ActiveX control from which socket connection the application wants to read data. The OnReceiveOOB event will only occur if the Option property has previously been set to OPTION_RECV_OOB_ON.
The Result property will contain the total number of bytes read from the out-of-band receive buffer. The Result property will contain a value less than or equal to the value specified by the ReceiveLen property.
This property can only be read at run time while a connection is established. There is no default value for this property.
Example
Dim UrgData As String
Server.Connection = Connection
UrgData = Server.ReceiveOOB
Summary
Size in bytes of receive buffer.
Description
The ReceiveSize property is used to specify the size of the receive buffer of a TCP Server control. Applications which will receive large amounts of data can increase the size of the receive buffer. By increasing the receive buffer size, the ActiveX control may be able to increase throughput for some applications.
The SendSize property can be used to adjust the size of the send buffer for applications which will send large amounts of data. The ReceiveSize and the SendSize properties are independent of each other.
Most applications will not need to modify this property. Most protocol stacks do not allow the send and receive buffer sizes to be less than 1024 bytes.
This property can be changed at any time before the socket is put into listening mode (by setting the Action property to ACTION_LISTEN or by calling the Listen method). The default value of this property is 1024 bytes.
Example
Server.ReceiveSize = 4096
Summary
Remote port used for connection.
Description
The RemotePort property specifies the port on the remote machine with which a connection has been established. Server TCP sockets do not know ahead of time to which remote port they will be connecting until a connection request arrives.
The RemotePort property is set when a connection is established with a client (by setting the Action property to ACTION_ACCEPT or by calling the Accept method in an OnAccept event). The TCP Server ActiveX control sets the RemotePort property to the port on the remote machine with which a connection was established.
The value of the RemotePort property identifies the port used in the last connection with the remote machine. This value will change with each session that is established between the client and the TCP server. An application can save the value of the RemotePort property along with the socket connection handle delivered by the OnConnect event and the HostAddress property for each established connection to uniquely identify that connection.
This property is read only and can not be set by the application. There is no default value for this property.
Example
Sub Server_OnConnect (Connection
As Integer)
If Server.RemotePort <> 1000 Then
Server.Connection = Connection
Server.Action = ACTION_DISCONNECT
End If
End Sub
Summary
Number of bytes sent or received.
Description
The Result property contains the number of bytes that were sent during a send operation and the number of bytes read during a receive operation. This property can only be read by the application and cannot be changed.
Data is sent by assigning a string to the Send property. Care should be taken not to exceed the buffer and transport capabilities of the underlying protocol stack. When using the TCP protocol, in general, no more than 512 bytes of data should be assigned to the Send property at any one time.
The Result property must be checked each time after assigning data to the Send property or after accessing the Receive property. If an error occurs during the send operation, then the Result property will contain the number of bytes that were successfully sent before the error occurred. Hence, this property may be used to verify whether all of the data or only a portion has been sent to the remote host. The Error property will contain any error code returned by the protocol stack.
Data is received by accessing the Receive property. This property can only be accessed by assigning its value to another string while a connection is established. Whenever the property is assigned to a string, as many bytes of data as possible up to the number specified by the ReceiveLen property are copied from the receive buffer into that string.
The Result property must be checked each time the Receive property is accessed to read the data sent by the remote machine. The ReceiveLen property specifies the maximum number of bytes that can be read from the receive buffer and the Result property specifies the exact number of bytes that were read from the receive buffer. The Result property will always contain a value less than or equal to the value specified by the ReceiveLen property.
This property can only be read at run time while a connection is established. There is no default value for this property.
Example
Server.Send = "This is
a test"
If Server.Result = 14 Then
MsgBox "Message sent successfully", 64, "Sample Program"
End If
Summary
Send buffer.
Description
The Send property is used to transfer data to the remote machine over an established connection. Data is sent by assigning a string to this property. Care should be taken not to exceed the buffer and transport capabilities of the underlying protocol stack. Before sending data to the remote machine, the application must set the Connection property to the socket connection handle returned by the OnConnect event for that particular connection.
Most TCP/IP stacks are able to transfer multiple 512 byte chunks of data in quick succession. Because of the stream nature of the TCP protocol, every assignment of data to the Send property does not necessarily correspond to a packet being sent over the network. Data may be split up over more than one packet or several buffers may be combined and sent as a single packet.
The Result property will contain the total number of bytes sent. If no error occurred, then the Result property will be equal to the number of bytes assigned to the Send property.
Incoming data can be read by accessing the Receive property in response to OnReceive events. The ReceiveCount property can be used to check how much data (if any) is available to be read.
This property can only be written to at run time while a connection is established. There is no default value for this property.
Example
Server.Send = "This is a test"
Summary
Send buffer for out-of-band data.
Description
The SendOOB property is used to transfer out-of-band data to the remote machine over an established TCP connection. Out-of-band data is sent by assigning a string to this property. Care should be taken not to exceed the buffer and transport capabilities of the underlying protocol stack. Before sending out-of-band data to the remote machine, the application must set the Connection property to the socket connection handle returned by the OnConnect event for that particular connection.
Most TCP/IP stacks are able to transfer multiple 512 byte chunks of data in quick succession. Because of the stream nature of the TCP protocol, every assignment of data to the SendOOB property does not necessarily correspond to a packet being sent over the network. Data may be split up over more than one packet or several buffers may be combined and sent as a single packet.
The Result property will contain the total number of bytes sent. If no error occurred, then the Result property will be equal to the number of bytes assigned to the SendOOB property.
Incoming out-of-band data can be read by accessing the ReceiveOOB property in response to OnReceiveOOB events.
This property can only be written to at run time while a connection is established. There is no default value for this property.
Example
' UrgData contains out-of-band data
to be sent to the remote machine.
Server.SendOOB = UrgData
Summary
Size in bytes of send buffer.
Description
The SendSize property is used to specify the size of the send buffer of the TCP Server ActiveX control. Applications which will send large amounts of data can increase the size of the send buffer. By increasing the send buffer size, the ActiveX control may be able to increase throughput for some applications.
The ReceiveSize property can be used to adjust the size of the receive buffer for applications which will receive large amounts of data. The SendSize and the ReceiveSize properties are independent of each other.
Most applications will not need to modify this property. Most protocol stacks do not allow the send and receive buffer sizes to be less than 1024 bytes.
This property can be changed at any time before the socket is put into listening mode by setting the Action property to ACTION_LISTEN (or by calling the Listen method). The default value of this property is 1024 bytes.
Example
Server.SendSize = 4096
Summary
Timeout when sending data.
Description
The SendTimeout property specifies in seconds how long the TCP Server ActiveX control must wait for the underlying protocol stack to buffer the data in the Send property. The default value is 20 seconds.
Usually, this property should be preset during design time to an appropriate value. However, an application can change the value of the SendTimeout property at any time to suit the particular environment.
If the send operation times out, then an OnError event is fired, notifying the application that not all of the data was transferred. The Result property will contain the total number of bytes of data sent before the error occurred and the Error property will contain the error code returned by the underlying protocol stack. If no error occurred, then the Result property will be equal to the number of bytes of data assigned to the Send property.
Most applications will not need to modify this property.
This property can be changed at any time. The default value of this property is 20 seconds.
Example
Dim Message As String
Message = "This is a test"
Server.SendTimeout = 15
Server.Send = Message
Summary
Official service name.
Description
The ServiceName property specifies the official name of a service. A service is identified by the protocol name and the port on which the service is available. This property must be set before setting the Convert property to SVC_NAME_TO_PORT.
If the Convert property is set to either SVC_NAME_TO_PORT or SVC_PORT_TO_NAME, then the name of the protocol to use when contacting the service must also be specified in the ProtocolName property.
The TCP Server ActiveX control can look up either the service port given the name or the service name given the port. To convert the service name to the port, set the ServiceName property to the name of the service and then set the Convert property to SVC_NAME_TO_PORT. To retrieve the service name, set the ServicePort property to the port of the service and then set the Convert property to SVC_PORT_TO_NAME.
This property can only be changed at run time. There is no default value for this property.
Example
Server.ServiceName = "daytime"
Server.ProtocolName = "tcp"
Server.Convert = SVC_NAME_TO_PORT
' Server.ServicePort will now contain the port number of the "daytime"
service for "tcp" protocol.
Summary
Port number on which service is available.
Description
The ServicePort property specifies the port on which a particular service is available. A service is identified by the protocol name and the service port. This property must be set before setting the Convert property to SVC_PORT_TO_NAME.
If the Convert property is set to either SVC_NAME_TO_PORT or SVC_PORT_TO_NAME, then the name of the protocol to use when contacting the service must also be specified in the ProtocolName property.
The TCP Server ActiveX control can look up either the service port given the name or the service name given the port. To convert the service name to the port, set the ServiceName property to the name of the service and then set the Convert property to SVC_NAME_TO_PORT. To retrieve the service name, set the ServicePort property to the port of the service and then set the Convert property to SVC_PORT_TO_NAME.
This property can only be changed at run time. There is no default value for this property.
Example
Server.ServicePort = 13
Server.ProtocolName = "tcp"
Server.Convert = SVC_PORT_TO_NAME
' Server.ServiceName will now contain "daytime".
Summary
Connection request has been received and is ready to be accepted.
Description
The OnAccept event occurs when a connection request has been received from a remote machine. This event will only occur on TCP sockets which have been set to listening mode by setting the Action property to ACTION_LISTEN (or by calling the Listen method).
If an application decides not to accept the request, then this event can be ignored. Once an application decides to accept the incoming connection request, it must set the Action property to ACTION_ACCEPT (or call the Accept method). If the connection can be established, then the OnConnect event will occur before the next line of code is reached.
If a connection request is not accepted, then the client may resend the request. In this case, the application will receive more than one OnAccept event.
While handling the OnAccept event, an application should not perform tasks which have the potential of requiring a lot of time to complete, such as generating a message box. A substantial delay could cause the underlying protocol to reject the connection request.
Example
Sub Server_OnAccept ()
Server.Action = ACTION_ACCEPT
End Sub
Summary
Listening connection has been closed.
Description
The OnClose event occurs in response to setting the Action property to ACTION_CLOSE (or in response to the Close method). When the server is no longer required to be in listening mode (to accept incoming connection requests), then the Action property should be set to ACTION_CLOSE (or call the Close method). This will trigger an OnClose event.
Although the server is no longer listening for new connection requests, the application may still be connected to clients and can continue communicating over previously established connections. However, any further requests for connections will not be received by the server.
When this event occurs in response to setting the Action property to ACTION_CLOSE (or in response to the Close method), it will occur before the statement following the assignment of ACTION_CLOSE to the Action property (or the call to the Close method) is reached.
Normally, an application should simply set a flag in response to this event. Then, this flag can be checked directly after the assignment of ACTION_CLOSE to the Action property (or the call to the Close method) to make sure that the TCP Server ActiveX control is no longer listening for connection requests.
Example
Sub Server_OnClose ()
Listening = False
End Sub
Summary
Connection has been established.
Description
The OnConnect event occurs in response to setting the Action property to ACTION_ACCEPT (or in response to the Accept method) on a listening TCP server socket after an OnAccept event occurred.
This event will occur before the statement following the assignment of ACTION_ACCEPT (or the Accept method) to the Action property is reached.
Normally, an application should simply set a flag in response to this event. Then, this flag can be checked directly after the ACTION_ACCEPT operation (or the Accept method) to make sure that the connection was actually established.
If the connection could not be established, then an OnError event will be fired instead of the OnConnect event. If the connection can be established, an OnConnect event will be fired with the socket connection handle for the newly established connection. The application must save this handle delivered in the OnConnect event, so that it can set the Connection property to the appropriate value for further socket operations.
While handling the OnConnect event, an application should not perform tasks which have the potential of requiring a lot of time to complete, such as generating a message box
Example
Sub Server_OnConnect (Connection
As Integer)
Conns [Connection].Connected = True
End Sub
Summary
Connection has been closed.
Description
The OnDisconnect event occurs usually in response to setting the Action property to ACTION_DISCONNECT (or in response to the Disconnect method). In some cases, the remote machine may close a connection (for example because of a long period of inactivity or because all data has been transferred). This will also trigger an OnDisconnect event. In this case, the application must still set the Action property to ACTION_DISCONNECT (or call the Disconnect method) to free up all the resources allocated for the connection. However, this should not be done during the OnDisconnect event because it might result in an infinite loop. Also, the Connection property must be set to the appropriate socket connection handle before setting the Action property to ACTION_DISCONNECT.
This event delivers the socket connection handle for the connection that was closed.
If this event occurs in response to setting the Action property to ACTION_DISCONNECT (or in response to the Disconnect method), it will occur before the statement following the assignment of ACTION_DISCONNECT (or the call to the Disconnect method) to the Action property is reached.
Normally, an application should simply set a flag in response to this event. Then, this flag can be checked directly after the ACTION_DISCONNECT action (or the Disconnect method) to make sure that the connection was actually terminated.
Example
Sub Server_OnDisconnect (Connection
As Integer)
If Conns [Connection].Connected = True Then
Conns [Connection].Connected = False
Server.Connection = Connection
Server.Action = ACTION_DISCONNECT
End If
End Sub
Summary
Local error has occurred.
Description
The OnError event occurs when a property is accessed in an illegal way or when a connection with the remote machine cannot be established. The table below lists all possible error codes delivered by this event.
Value | Meaning |
ERR_IN_ACTION | Another action is in progress. |
ERR_CHANGE_LOCAL_PORT | Cannot change local port while listening. |
ERR_CHANGE_RECV_SIZE | Cannot change receive buffer size while listening. |
ERR_CHANGE_SEND_SIZE | Cannot change send buffer size while listening. |
ERR_CANNOT_GET_SOCKET | Unable to allocate socket. |
ERR_CANNOT_BIND_SOCKET | Unable to bind socket. |
ERR_CANNOT_SETUP_SOCKET | Unable to setup socket. |
ERR_CANNOT_LISTEN_SOCKET | Unable to listen. |
ERR_NOT_LISTENING | Server is not listening. |
ERR_CANNOT_ACCEPT | Unable to accept connection. |
ERR_CANNOT_RECV | Unable to receive data. |
ERR_CANNOT_RECV_COUNT | Unable to determine receive count. |
ERR_CANNOT_SEND | Unable to send data. |
ERR_NO_OPTION_VALUE | Value of socket option not defined. |
ERR_CANNOT_GET_LOCAL | Unable to obtain local IP address. |
ERR_CANNOT_RECV_OOB | Unable to receive out-of-band data. |
ERR_CANNOT_SEND_OOB | Unable to send out-of-band data. |
The following describes each error in more detail.
ERR_IN_ACTION
Another action is already in progress.
ERR_CHANGE_LOCAL_PORT
Local port cannot be changed while the server is listening on that
port.
ERR_CHANGE_RECV_SIZE
Size of receive buffer cannot be changed while listening or when clients
are connected to the server.
ERR_CHANGE_SEND_SIZE
Size of send buffer cannot be changed while connected or when clients
are connected to the server.
ERR_CANNOT_GET_SOCKET
Unable to allocate socket.
ERR_CANNOT_BIND_SOCKET
Unable to bind socket to local address.
ERR_CANNOT_SETUP_SOCKET
Unable to set up socket. The SendSize and ReceiveSize properties may
be set incorrect values.
ERR_CANNOT_LISTEN_SOCKET
Unable to listen on socket.
ERR_NOT_LISTENING
Cannot accept on a socket that is not listening. The Action property
must be set to ACTION_LISTEN (or the Listen method must be called) before
setting it to ACTION_ACCEPT (or before calling the Accept method).
ERR_CANNOT_ACCEPT
Unable to accept incoming TCP connection.
ERR_CANNOT_RECV
Must be connected before accessing receive buffer.
ERR_CANNOT_RECV_COUNT
Must be connected before accessing receive count.
ERR_CANNOT_SEND
Unable to send data to remote host.
ERR_NO_OPTION_VALUE
Value of socket option not defined. Set the OptionValue property to
the time-out for linger before setting the Option property to OPTION_LINGER_ON
(also see the Linger method).
ERR_CANNOT_GET_LOCAL
Unable to obtain the local host's name or dotted decimal internet address.
ERR_CANNOT_RECV_OOB
Unable to receive out-of-band data from remote host. Out-of-band data
can only be received over TCP connections. Make sure that the Protocol
property has been set to PROTOCOL_TCP.
ERR_CANNOT_SEND_OOB
Unable to send out-of-band data to remote host. Out-of-band data can
only be sent over TCP connections. Make sure that the Protocol property
has been set to PROTOCOL_TCP.
Example
Sub Server_OnError (ErrorCode
As Integer)
If ErrorCode = ERR_CANNOT_LISTEN_SOCKET Then
MsgBox "Unable to listen on socket", 64, "Sample Program"
End If
End Sub
Summary
More data has been added to the receive buffer.
Description
The OnReceive event occurs when more data arrives from the remote machine over a connected socket. The event does not actually deliver the data to the application, but instead, expects that the application will access the Receive property to obtain all data waiting in the receive buffer.
Each OnReceive event usually corresponds to one packet of data arriving for the socket. Depending on the underlying protocol stack, OnReceive events may also be fired after each access to the receive buffer through the Receive property if not all available data has been read. In some of these environments, for example Windows Sockets, no duplicate OnReceive events will be fired. This means that only one OnReceive event will occur until the Receive property has been accessed even if more data has arrived.
An application must be able to deal with OnReceive events which occur even though no data is available to receive from the socket. This condition may occur if during one event the application reads all the available data including data associated with a subsequent event.
The ReceiveCount property can be checked to determine how many bytes of data are available to read. Because of the interrupt driven nature of network communications, the value of the ReceiveCount property can change quickly at any time. An application should not rely on this value for an extended period of time without rechecking it.
The ReceiveLen property specifies how many bytes of data will be obtained from the receive buffer every time the Receive property is accessed.
The Result property will contain the total number of bytes read from the receive buffer. The Result property will contain a value less than or equal to the value specified by the ReceiveLen property.
An application does not have to rely on the OnReceive event to notify it of incoming data. Instead of or in addition to this event, the application may check the value of the ReceiveCount property to find out if any data is available.
For more information on how to receive data, please check the reference pages of the Receive, ReceiveCount, ReceiveLen and Result properties.
While handling the OnReceive event, an application should not perform tasks which have the potential of requiring a lot of time to complete, such as generating a message box. A substantial delay could cause the application to not receive subsequent OnReceive events.
Example
Sub Server_OnReceive (Connection
As Integer)
Dim Message As String
Server.Connection = Connection
Message = Server.Receive
End Sub
Summary
More out-of-band data has been received.
Description
The OnReceiveOOB event occurs when more out-of-band data arrives from the remote machine over a connected TCP socket. The event does not actually deliver the data to the application, but instead, expects that the application will access the ReceiveOOB property to obtain the out-of-band data waiting in the out-of-band receive buffer. This event will be fired only if the Option property has been set to OPTION_RECV_OOB_ON (also see the RecvOOB method). This option enables notification on arrival of out-of-band data.
Each OnReceiveOOB event usually corresponds to one packet of out-of-band data arriving for the socket. Depending on the underlying protocol stack, OnReceiveOOB events may also be fired after each access of the out-of-band receive buffer through the ReceiveOOB property if not all available out-of-band data has been read. In some of these environments, for example Windows Sockets, no duplicate OnReceiveOOB events will be fired. This means that only one OnReceiveOOB event will occur until the ReceiveOOB property has been accessed even if more out-of-band data has arrived.
An application must be able to deal with OnReceiveOOB events which occur even though no out-of-band data is available on the socket. This condition may occur if during one event the application reads all the available out-of-band data including out-of-band data associated with a subsequent event.
The ReceiveLen property specifies how many bytes of out-of-band data will be obtained from the out-of-band receive buffer every time the ReceiveOOB property is accessed.
The Result property will contain the total number of bytes read from the out-of-band receive buffer. The Result property will contain a value less than or equal to the value specified by the ReceiveLen property.
For more information on how to receive out-of-band data, please check the reference pages of the Option, ReceiveOOB, ReceiveLen and Result properties.
While handling the OnReceiveOOB event, an application should not perform tasks which have the potential of requiring a lot of time to complete, such as generating a message box. A substantial delay could cause the application to not receive subsequent OnReceiveOOB events.
Example
Sub Server_OnReceiveOOB (Connection
As Integer)
Dim UrgData As String
Server.Connection = Connection
UrgData = Server.ReceiveOOB
End Sub
Summary
Accept a pending connection request.
Syntax
Boolean Accept () |
Description
Whenever a client sends a connection request over the network to the port on which the server is listening, an OnAccept event is fired. In response to the OnAccept event, the application must call the Accept method to establish a connection with the client.
The Accept method takes no parameters and returns a boolean. If an incoming connection request can be successfully established, then the method returns True; otherwise, it returns False. The application should ensure that the method was successfully executed by checking the return value.
If the connection can be established, then the OnConnect event will occur before the next line of code is reached. The OnConnect event will contain a socket connection handle which must be saved by the application. Since more than one client can connect to the server, the only way to identify an established connection is through this socket connection handle. Once a connection has been established, data can be sent with the Send property and available data can be received with the Receive property.
However, before sending or receiving data or closing a connection, the application must identify the connection on which this operation is to be performed. To identify the connection, the Connection property must be set to the socket connection handle obtained during the OnConnect event for the specific connection.
Calling this method is equivalent to setting the Action property to ACTION_ACCEPT.
Example
Result = Server.Accept ()
If Result = False Then
MsgBox "Cannot accept request", 64, "Sample Program"
End If
Summary
Convert host address to dotted decimal.
Syntax
String AddrToDecimal (HostAddress) | ||
HostAddress | Long |
Description
The AddrToDecimal method converts the specified internet address passed as a parameter into the dotted decimal address of the host.
The AddrToDecimal method takes a host address (HostAddress) as its parameter and returns a string. This method converts the host address to its corresponding dotted decimal address. The result of this lookup will be returned as a string.
If the HostAddress can be successfully converted to its dotted decimal address, then the method returns the dotted decimal address; otherwise, it returns an empty string. If the given host address is 0, then the HostName property will also be cleared. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the HostConvert property to CONVERT_ADDRESS_TO_DECIMAL.
Example
Name = Server.AddrToDecimal
(Server.HostAddress)
If Name = "" Then
MsgBox "Cannot convert host address to dotted decimal format",
64, "Sample Program"
End If
Summary
Convert host address to host name.
Syntax
String AddrToName (HostAddress) | ||
HostAddress | Long |
Description
The AddrToName method converts the internet address passed as parameter into the name of the host. The control first checks if the specified internet address is defined in the local host's database. If the address is not found, then the control will send queries over the network to a name server.
The AddrToName method takes a host address (HostAddress) as its parameter and returns a string. This method takes the HostAddress and converts to the corresponding host name. The result of this lookup will be returned as a string.
If the host address can be successfully converted to its host name, then the method returns the host name; otherwise, it returns an empty string. If the given host address is 0, then the HostName property will also be cleared. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to as setting the HostConvert property to CONVERT_ADDRESS_TO_NAME.
Example
HostName = Server.AddrToName
(Server.HostAddress)
If HostName = "" Then
MsgBox "Cannot convert the host address to a host name", 64,
"Sample Program"
End If
Summary
Stop listening for incoming connection requests.
Syntax
Boolean Close () |
Description
The Close method stops listening for incoming connection requests. If no more connection requests will be accepted by the server on a listening socket, then the listening socket must be closed by calling this method. Once the listening socket is closed, the OnClose event will occur before the next line of code is reached. Applications must close the listening socket before terminating.
The Close method takes no parameters and returns a boolean. If the listening socket can be successfully terminated, then the method returns True; otherwise, it returns False. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the Action property to ACTION_CLOSE.
Example
Result = Server.Close ()
If Result = False Then
MsgBox "Unable to close listening socket", 64, "Sample Program"
End If
Summary
Close accepted connection
Syntax
Boolean Disconnect (Connection) | ||
Connection | Integer |
Description
If a connection is no longer needed, then the Disconnect method must be called. Once the socket is closed, the OnDisconnect event will occur before the next line of code is reached. To identify which connection was closed, the socket connection handle is included in the OnDisconnect event. Applications must disconnect any accepted connections before terminating.
The Disconnect method takes a connection id (Connection) as its parameter and returns a boolean. If a connection is successfully terminated, then the method returns True; otherwise, it returns False. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the Action property to ACTION_DISCONNECT.
Example
Connection = 1
Result = Server.Disconnect (Connection)
If Result = False Then
MsgBox "Unable to close connection", 64, "Sample Program"
End If
Summary
Send or not send keep-alive TCP packets.
Syntax
Boolean KeepAlive (Enable) | ||
Enable | Boolean |
Description
An application may request the underlying protocol stack to enable the use of keep-alive packets on TCP connections (provided the protocol stack supports the use of keep-alives) by calling the KeepAlive method with Enable set to True. The send and time-out intervals must be specified as required by the protocol stack in use. To disable keep-alive probes, call this method with Enable set to False (this is the default setting).
The KeepAlive method takes an enable flag (Enable) as its parameter and returns a boolean. If the keep-alive probes can be successfully enabled or disabled, then the method returns True; otherwise, it returns False. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the Option property to OPTION_KEEPALIVE_ON or OPTION_KEEPALIVE_OFF.
This method can be called at any time before or after a connection is established.
Example
Result = Server.KeepAlive (True)
If Result = False Then
MsgBox "Cannot enable keep-alive probes", 64, "Sample Program"
End If
Summary
Set or not set linger time-out for close socket operation.
Syntax
Boolean Linger (Enable, OptionValue) | ||
Enable | Boolean | |
OptionValue | String |
Description
The Linger method controls the behavior of the socket while disconnecting.
The Linger method takes an enable flag (Enable) and an timeout value (OptionValue) as its parameters and returns a boolean. If linger time-out can be successfully enabled or disabled, then the method returns True; otherwise, it returns False. The application should ensure that the method was successfully executed by checking the return value.
If the method is called with Enable set to True, then the socket is not closed until all data buffered in the send buffer is transmitted or the given time-out has been exceeded. The time-out value in seconds must be specified as the OptionValue parameter. If the OptionValue parameter is set to 0 with linger enabled, then the connection will be reset. If the method is called with Enable set to False, then the underlying protocol stack will close without waiting for buffered data to be sent. The TCP Server ActiveX control by default enables linger with a three second time-out.
Calling this method is equivalent to setting the Option property to OPTION_LINGER_ON or OPTION_LINGER_OFF.
This method can be called at any time before or after a connection is established.
Example
Result = Server.Linger (True,
"5")
If Result = False Then
MsgBox "Cannot set linger time-out", 64, "Sample Program"
End If
Summary
Listen for incoming connection request.
Syntax
Boolean Listen () |
Description
The TCP Server ActiveX control can accept connections only when it is in listening mode. Before calling the Listen method, the LocalPort property must be set to the local port on which the server will be listening for connection requests. The default port cannot be used for TCP server sockets. Once the server is in listening mode, it can accept incoming connection requests. No event is generated in response to a successful listen.
The Listen method takes no parameters and returns a boolean. If the TCP server can be successfully set to listening mode, then the method returns True; otherwise, it returns False. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the Action property to ACTION_LISTEN.
Example
Server.LocalPort = 3000
Result = Server.Listen ()
If Result = False Then
MsgBox "Unable to listen", 64, "Sample Program"
End If
Summary
Convert host name to host address.
Syntax
Long NameToAddr (HostName) | ||
HostName | String |
Description
The NameToAddr method converts the host name (or the host address specified in dotted decimal notation) into the internet address of the host. If specified host name contains an address in dotted decimal notation (for example, 127.43.101.12), then the control will simply convert the string to an internet address. Otherwise, the control first checks if the specified host is defined in the local host's database. If the host is not found, then the control will send queries over the network to a name server.
The NameToAddr method takes a host name (HostName) as its parameter and returns a long. This method takes the HostName parameter and converts it to the corresponding host address. The result of this lookup will be returned as a long.
If the host name can be successfully converted to its host address, then the method returns the host address long; otherwise, it returns 0. If the given host name cannot be resolved, then the HostAddress property will also be set to 0. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the HostConvert property to CONVERT_NAME_TO_ADDRESS.
Example
HostAddress = Server.NameToAddr
("speedy")
If HostAddress = 0 Then
MsgBox "Cannot convert the specified host name to its host address",
64, "Sample Program"
End If
Summary
Convert protocol name to protocol number.
Syntax
Integer ProtoNameToNumber (ProtocolName) | ||
ProtocolName | String |
Description
The ProtoNameToNumber method converts the protocol name into the protocol number associated with the protocol name.
The ProtoNameToNumber method takes a protocol name (ProtocolName) as its parameter and returns an integer. This method takes the protocol name parameter and converts it to the associated protocol number. The result of this lookup will be returned as an integer.
If the protocol name can be successfully converted to its protocol number, then the method returns the protocol number; otherwise, it returns 0. If the given protocol name cannot be resolved, then the ProtocolNumber property will also be set to 0. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the Convert property to PROTO_NAME_TO_NUMBER.
The Error property can be checked to obtain the error code returned by the underlying protocol stack.
Example
ProtocolNumber = Server.ProtoNameToNumber
("tcp")
If ProtocolNumber = 0 Then
MsgBox "Cannot obtain protocol number", 64, "Sample Program"
End If
Summary
Convert protocol number to protocol name.
Syntax
String ProtoNumberToName (ProtocolNumber) | ||
ProtocolNumber | Integer |
Description
The ProtoNumberToName method converts the protocol number into the corresponding protocol name.
The ProtoNumberToName method takes a protocol number (ProtocolNumber) as its parameter and returns a string. This method takes the protocol number parameter and converts it to the corresponding protocol name. The result of this lookup will be returned as a string.
If the protocol number can be successfully converted to its protocol name, then the method returns the protocol name string; otherwise, it returns an empty string. If the given protocol number cannot be resolved, then the ProtocolName property will also be cleared. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the Convert property to PROTO_NUMBER_TO_NAME.
The Error property can be checked to obtain the error code returned by the underlying protocol stack.
Example
ProtocolName = Server.ProtoNumberToName
(1)
If ProtocolName = "" Then
MsgBox "Cannot obtain protocol name", 64, "Sample Program"
End If
Summary
Receive binary data.
Syntax
Long ReceiveB (Buffer) | ||
Buffer | Variant |
Description
The ReceiveB method is used to access binary data that has been sent by the remote machine. Whenever this method is called, as many bytes of data as possible (up to the number specified by the ReceiveLen property) are copied to the buffer parameter passed to it.
The ReceiveB method takes a variant buffer (Buffer) as its parameter and returns a long. If the operation is successful, then the method fills the variant buffer with data received and returns the number of bytes that was received; otherwise, it sets the buffer to NULL and returns 0. The application should ensure that the method was successfully executed by checking variant buffer or the return value.
Usually, this method is called during an OnReceive event. This event informs the application that more data has arrived from the connected host. At this point, the application should read all the data available and process it. The ReceiveCount property can be used to find out how many total bytes of data are waiting to be read.
If the ReceiveLen property is set to a value less than the ReceiveCount property, then the application may have to call the ReceiveB method more than once to read all available data. In general, the application should get data from the receive buffer until no more data is available. This condition can be detected by checking the value returned by the ReceiveB method. As soon as this value is zero, all data has been read.
Since the ReceiveLen property can be changed at any time (even while connected), an application could assign the value of the ReceiveCount property to ReceiveLen. Any subsequent call to the ReceiveB method would then copy all available data to the buffer parameter passed to the method. This approach is not advisable if very large amounts of data are being received.
The Result property and the return value of the ReceiveB method will contain the total number of bytes read. The Result property will contain a value less than or equal to the value specified by the ReceiveLen property.
This method can only be read at run time while a connection is established.
Example
Dim Buffer() As Byte
Dim Siz As Long
Dim i As Integer
Siz = Server.ReceiveB (Buffer)
If Siz > 0 Then
Open "c:\abc.exe" For Binary Access Write As #1
For i = 1 To Siz
Put #1, i, Buffer (x)
Next i
Close #1
Else
MsgBox "Cannot receive binary data", 64, "Sample Program"
End If
Summary
Receive out-of-band data separately or as regular data.
Syntax
Boolean RecvOOB (Enable) | ||
Enable | Boolean |
Description
Out-of-band data (or TCP urgent data) can be delivered to the user either separately from regular data or as part of regular data. If an application needs to process out-of-band data apart from regular data, then the RecvOOB method must be called with Enable set to True. In this case, the arrival of out-of-band data will trigger the OnReceiveOOB event. The ReceiveOOB property can then be used to access the out-of-band data. To receive out-of-band data as regular data, call this method with Enable set to False. By default, out-of-band data is received as part of the regular data stream. The out-of-band options are available only for TCP connections.
The RecvOOB method takes an enable flag (Enable) as its parameter and returns a boolean. If operation is successful, then the method returns True; otherwise, it returns False. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the Option property to OPTION_RECV_OOB_ON or OPTION_RECV_OOB_OFF.
This method can be called at any time before a connection is established.
Example
Result = Server.RecvOOB (True)
If Result = False Then
MsgBox "Cannot receive out-of-band data", 64, "Sample Program"
End If
Summary
Send binary data.
Syntax
Boolean SendB (Buffer, Bytes) | ||
Buffer | Variant | |
Bytes | Long |
Description
The SendB method is used to transfer binary data to the remote machine over an established connection. Care should be taken not to exceed the buffer and transport capabilities of the underlying protocol stack. Before sending data to the remote machine, the application must set the Connection property to the socket connection handle returned by the OnConnect event for that particular connection.
The SendB method takes a variant buffer (Buffer) and a long byte (Bytes) as its parameters and returns a boolean. The variant buffer has to be set to the data to be sent. The bytes parameter has to be set to the number of bytes of data (or the size of the buffer parameter) to be sent. If operation is successful, then the method returns True; otherwise, it returns False. The application should ensure that the method was successfully executed by checking the return value.
Most TCP/IP stacks are able to transfer multiple 512 byte chunks of data in quick succession. Because of the stream nature of the TCP protocol, every call to the SendB method with data does not necessarily correspond to a packet being sent over the network. Data may be split up over more than one packet or several buffers may be combined and sent as a single packet.
The Result property will contain the total number of bytes sent. If no error occurred, then the Result property will be equal to the number of bytes passed to the SendB method.
Incoming data can be read by calling the ReceiveB method in response to OnReceive events. The ReceiveCount property can be used to check how much data (if any) is available to be read.
This method can only be called at run time while a connection is established.
Example
Dim Buffer() As Byte
Dim Bytes As Long
Dim i As Integer
Open "c:\abc.exe" For Binary Access Read As #1
Bytes = FileLen("c:\abc.exe")
For i = 1 To Bytes
Get #1, , Buffer(i)
Next i
Result = Server.SendB(Buffer, Bytes)
If Result = False Then
MsgBox "Cannot send binary data", 64, "Sample Program"
End If
Close #1
Summary
Convert service name to service port.
Syntax
Integer ProtoNameToNumber (ServiceName, ProtocolName) | ||
ServiceName | String | |
ProtocolName | String |
Description
The SvcNameToPort method converts the service name (associated with the protocol name) into the service port, where the service can be contacted. The name of the protocol is used when contacting the service.
The SvcNameToPort method takes a service name (ServiceName) and a protocol name (ProtocolName) as its parameters and returns an integer. This method takes the service name and the protocol name and converts it to the associated service port. The result of this lookup will be returned as an integer.
If the service name can be successfully converted to its service port, then the method returns the service port; otherwise, it returns 0. If the given service name cannot be resolved, then the ServicePort property will also be set to 0. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the Convert property to SVC_NAME_TO_PORT.
The Error property can be checked to obtain the error code returned by the underlying protocol stack.
Example
ServicePort = Server.SvcNameToPort
("daytime", "tcp")
If ServicePort = 0 Then
MsgBox "Cannot obtain service port", 64, "Sample Program"
End If
Summary
Convert service port to service name.
Syntax
String ServPortToName (ServicePort, ProtocolName) | ||
ServicePort | Integer | |
ProtocolName | String |
Description
The SvcPortToName method converts the service port (associated with the protocol name) into the corresponding service name.
The SvcPortToName method takes a service port (ServicePort) and a protocol name (ProtocolName) as its parameter and returns a string. This method takes the service port and the protocol name and converts it to the corresponding service name. The result of this lookup will be returned as a string.
If the service port can be successfully converted to its service name, then the method returns the service name; otherwise, it returns an empty string. If the given service port cannot be resolved, then the ServiceName property will also be cleared. The application should ensure that the method was successfully executed by checking the return value.
Calling this method is equivalent to setting the Convert property to SVC_PORT_TO_NAME.
The Error property can be checked to obtain the error code returned by the underlying protocol stack.
Example
ServiceName = Server.SvcPortToName
(13, "tcp")
If ServiceName = "" Then
MsgBox "Cannot obtain service name", 64, "Sample Program"
End If