Library tutorials & articles
SocketWrench Control
Establishing a Connection
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.
Related articles
Related discussion
-
How to POP3 in C#
by converter2009 (9 replies)
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
Related podcasts
-
Listener Feedback 67
This mailbag episode includes FASM, scripts, sockets, SSL/TLS, HTTPS, Windows 7's XP mode, and more. Security Now wiki shownotes For 16kpbs versions, transcripts, and notes (including fixes), visit Steve's site: grc.com, also the home of the best disk maintenance and recovery utility ever written...
I need some help. I want to make the server client program work over the internet, not just a LAN. So my friend can use the client, and I can be the server and we can sedn messages back and forth. Can someone help me with this?
we have established connection between server & client. It works ok when we pass queries from just one form. when we want to load many forms at a time with only a single connection some error has occured. only the first form loads from the database without error when the next form loads there is some error in the connection.
could you help us?
This thread is for discussions of SocketWrench Control.