The following properties, methods and events are available for use by your application:
Initialize the control and load the Windows Sockets library for the current process. This method is normally not used if the control is placed on a form in languages such as Visual Basic. However, if the control is being created dynamically using a function similar to CreateObject, then the application must call this method to initialize the component before setting any properties or calling any other methods in the control.
Connect to the remote host, using either a host name or IP address. When an application calls this method, it will be acting as a client. This method creates the socket and must be called before your application attempts to exchange data with a server. For an asynchronous session, set the Blocking property to False.
Begin listening for incoming client connections. When an application calls this method, it will be acting as a server. Once the Listen method returns, the socket is created and that socket handle is used by the Accept method accept an incoming client connection. For an asynchronous session, set the Blocking property to False.
Accept a connection from a client. This method should only be called if the application has previously called the Listen method. If there is no client waiting to connect at the time this method is called, it will block until a client connects or the timeout period is reached.
Unload the Windows Sockets library and release any resources that have been allocated for the current process. This is the last method call that the application should make prior to terminating. This is only necessary if the application has previously called the Initialize method.
When a TCP connection is established, data is sent and received as a stream of bytes. The following methods can be used to send and receive data over the socket:
A low-level method used to read data from the socket and copy it to the string buffer or byte array provided by the caller. If the remote host closes the connection, this method will return zero after all the data has been read. If the method is successful, it will return the actual number of bytes written.
Read a line of text from the socket, up to an end-of-line character sequence or when the remote host closes the connection.
A high-level method used to read a stream of bytes and copy it to a string buffer or byte array provided by the caller. This method can be used to read an arbitrarily large amount of data in a single call.
A low-level method used to write data to the socket. If the method succeeds, the return value is the number of bytes actually written.
Write a line of text to the socket, terminating it with an end-of-line character sequence.
A high-level method used to write a stream of bytes to the socket. This method can be used to write an arbitrarily large amount of data to the socket in a single call.
This property is used to determine if there is data available to be read from the socket.
This property is used to determine if data can be written to the socket. In most cases this will return True, unless the internal socket buffers are full.
The control can be used to resolve host names into IP addresses, as well as perform reverse DNS lookups converting IP addresses into the host names that are assigned to them. The control will search the local system's host table first, and then perform a nameserver query if required.
This property can be used to set the IP address for a remote system that you wish to communicate with. If the address is valid and matches an entry in the host table, the HostName property will be changed to match the address.
This property should be set to the name of the remote system that you wish to communicate with. If the name is found in the host table, the HostAddress property is updated to reflect the IP address of the host. Note that it is legal to assign an IP address to this property, but it is not legal to assign a host name to the HostAddress property.
Several methods are provided to return information about the local host, including its fully qualified domain name, local IP address and the physical MAC address of the primary network adapter.
Return the fully qualified domain name of the local host, if it has been configured. If the system has not been configured with a domain name, then the machine name is returned instead.
Return the IP address of the local host. If a connection has been established, then the IP address of the network adapter that was used to establish the connection will be returned. This can be particularly useful for multi-homed systems that have more than one adapter and the application needs to know which adapter is being used for the connection.
Return the IP address assigned to the router that connects the local host to the Internet. This is typically used by an application executing on a system in a local network that uses a router which performs Network Address Translation (NAT).
Return the physical MAC address for the primary network adapter on the local system.
This array returns the IP addresses that are associated with the local network or remote dial-up network adapters configured on the system. The AdapterCount property can be used to determine the number of adapters that are available.