|
|
The SocketWrench software development kit includes an ActiveX
control which can be used in a variety of programming languages
such as Visual Basic, Visual C++, and Delphi. The control
implements the same general set of features and functions that are
available in the library. However, the control provides a simpler
programming interface.
To include the SocketWrench control in your project in Visual
Basic, simply select the Project|Components menu option and
select the SocketWrench Control. In other languages, follow the
normal steps that are taken to include an ActiveX control in your
development project. Note that if you have a previous version of
the freeware SocketWrench control installed on your development
system, you will see that control listed as well. Be sure to select
the correct version of the control.
Commonly Used Properties
Although SocketWrench has a large number of properties, only a
subset of them will be used with any frequency in your
applications. Here are the properties that you should become
familiar with first:
| Property |
Description |
| Blocking |
Gets and sets the blocking mode
for the socket. By default, sockets are blocking, and no socket
events will be generated by the control. |
| HostAddress |
Specifies the IP address of the
remote host that the socket will be sending data to or receiving
data from. Setting this property will automatically update the
HostName property. |
| HostName |
Specifies the name of the remote
host. Setting this property will automatically update the
HostAddress property. |
| Protocol |
Specifies the protocol to use for
this socket. Typical values are swProtocolTcp and
swProtocolUdp. |
| RemotePort |
Specifies the port number that a
remote server is listening. Setting this value causes the
RemoteService property to be updated. |
| RemoteService |
Specifies the service name of the
remote port a server is listening to. Setting this value causes the
RemotePort property to be updated. |
Commonly Used Methods
SocketWrench has a number of methods which are used to perform
some function, such as establishing a connection or sending and
receiving data. In many cases, there are optional arguments that
can be passed to these methods. If an argument is omitted, the
value of a previously set property may be used. If no value has
been specified, then a reasonable default value is typically
used.
| Methods |
Description |
| Connect |
This method is used to establish a
connection with a remote server. This method returns 0 if the
connection attempt was successful, or an error code which indicates
the cause of the failure. |
| Disconnect |
This method is used to terminate a
connection with a remote server. This method returns 0 if the
connection attempt was successful, or an error code which indicates
the cause of the failure. |
| Listen |
This method causes the control to
listen on a socket for incoming connections on the port specified
by the LocalPort or LocalService properties. If a socket has not
already been created, this action will create it. This method
returns 0 if the connection attempt was successful, or an error
code which indicates the cause of the failure. |
| Read |
This method reads the specified
number of bytes into a string buffer. The number of bytes actually
read is returned. A return value of 0 indicates that the remote
host has closed the socket connection, and a return value of -1
indicates that an error has occurred. |
| Write |
This method writes the specified
number of bytes from a string buffer to the socket. The number of
bytes actually written is returned. A return value of -1 indicates
that an error has occurred. |
|
|