The next step is to establish a connection with the echo server. This is done by including code in the Command1 button's Click event. The code should look like this:
Sub Command1_Click ()
Socket1.HostName = Trim$(Text1.Text)
Socket1.RemotePort = IPPORT_ECHO
Socket1.Action = SOCKET_CONNECT
End Sub
The Text1 edit control should contain the name or IP address of a system that has an echo server running (most UNIX and Windows NT based systems do have such a server). The properties which have been used to establish the connection are:
Property | Description |
---|---|
HostName | This property should be set to either the host name of the system that you want to connect to, or it's IP address in dot-notation. |
RemotePort | This property should be set to the number of the port which the remote application is listening on. Port numbers below 1024 are considered reserved by the system. In this example, the echo server port number is 7, which is specified by using the global constant IPPORT_ECHO. |
Action | This property initiates some action on the socket. The SOCKET_CONNECT action tells the control to establish a connection using the appropriate properties that have been set. A related action, SOCKET_CLOSE, instructs the control to close the connection, terminating the conversation with the remote server. |
Both HostName and RemotePort are known as reciprocal properties. This means that by changing the property, the another related property will also change to match it. For example, when you assign a value to the HostName property, the control will determine it's IP address and automatically set the HostAddress property to the correct value. The reciprocal property for RemotePort is the RemoteService property. For more information about these properties, refer to the SocketWrench/VB Technical Reference.
Because the socket is non-blocking (i.e.: the Blocking property has been set to a value of False), the program will not wait for the connection to be established. Instead, it will return immediately and respond to the Connect event in the SocketWrench/VB control. The code for that event should look like this:
Sub Socket1_Connect ()
Text2.Enabled = True
Text3.Enabled = True
End Sub
This tells the application that when a connection has been established, enable the edit controls so that the user can send and receive information from the server.
Comments