Properties can be described by several elements. Some are available to be set at design time, some are read only at runtime and are unavailable at design time, some may only be set at design time and are read only at runtime, and some can be set at both runtime and design time.
Another aspect of the property is the data type of the value. This can be a string, an integer, a long integer, or any other data type.
The third aspect of a property is the Syntax or usage for using the property in code.
BytesReceived Property
This property tells you the number of bytes currently in the receive buffer. This property is read-only and is unavailable at design time. The value returned is a long integer. An example of the syntax is:
myvar = MyWinsockControl.BytesReceived
An example of use would be to determine the size of a display area for the data or to see if there is any data in the buffer.
LocalHostName Property
This property returns the name of the local Host system. This property is read-only and is unavailable at design time. The value returned is a string. An example of the syntax is:
myvar = MyWinsockControl.LocalHostName
LocalIP Property
This property returns the local Host system IP address in the form of a string like XXX.XXX.XXX.XXX. This property is read-only and is unavailable at design time. The value returned is a string. An example of the syntax is:
myvar = MyWinsockControl.LocalIP
LocalPort Property
This property returns or sets the local port number. This property is read and write and is available at design time and runtime. The value returned is a long integer. An example of the syntax to read the property is:
myvar = MyWinsockControl.LocalPort
To set the property, you would use:
MyWinsockControl.LocalPort = 1001
An example of the use of this property is setting the port before using the Listen Method to set the port number for the application. This allows selection of the port at runtime or design time.
Protocol Property
This property returns or sets the protocol of either UDP or TCP. This property is read and write and is available at design time and runtime. (Note that at runtime the control must be closed--see the State Property entry later in this section) The value returned is 0 or the constant sckTCPProtocol or 1 or sckUDPProtocol. An example of the syntax to read the property is:
myvar = MyWinsockControl.Protocol
To set the property, you would use:
MyWinsockControl.LocalPort = sckTCPProtocol
RemoteHost Property
This property returns or sets the Remote Host. This property is read and write and is available at design time and runtime. The value returned is a string and can be specified either as an IP address (XXX.XXX.XXX.XXX) or a friendly name such as www.microsoft.com. An example of the syntax to read the property is:
myvar = MyWinsockControl.RemoteHost
To set the property, you would use:
MyWinsockControl.RemoteHost = "192.143.29.47"
Setting this property at runtime allows the Remote Host to be selected when the application starts based upon some criteria.
RemotePort Property
This property returns or sets the remote port number. This property is read and write and is available at design time and runtime. The value returned is a long integer. An example of the syntax to read the property is:
myvar = MyWinsockControl.RemotePort
To set the property, you would use:
MyWinsockControl.RemotePort = 1001
This property can be used to select the application to be contacted at the remote host.
State Property
Returns the state of the control as expressed by an enumerated list. This property is read-only and is unavailable at design time. The State property is set by using various methods and events.
The syntax to read the property is:
myvar = MyWinsockControl.State
The settings for the State Property are:
Constant |
Value |
Description |
sckClosed |
0 |
Default Closed |
sckOpen |
1 |
Open |
sckListening |
2 |
Listening |
sckConnectionPending |
3 |
Connection pending |
sckResolvingHost |
4 |
Resolving host |
sckHostResolved |
5 |
Host resolved |
sckConnecting |
6 |
Connecting |
sckConnected |
7 |
Connected |
sckClosing |
8 |
Peer is closing the connection |
sckError |
9 |
Error |
The state property will need to be checked before state changing methods are used. As an example, attempting to open a closed Winsock Control will result in an error.