Library tutorials & articles

SocketWrench Control

Closing the Socket

The last piece of code to add to the sample is to handle closing the socket when the program is terminated by selecting Close on the system menu. The best place to put socket cleanup code in the form's Unload event, such as:

Sub Form_Unload (Cancel As Integer)
If Socket1.Connected Then Socket1.Action = SOCKET_CLOSE
End Sub

This should be rather self-explanatory. The only new property that has been introduced is the Connected property, which is a Boolean flag. If it is True, then a connection has been established. With all of the properties and event code needed for the sample client application completed, all that's left to do is run the program!

The first thing that you'll probably notice is that if you specify an incorrect host name or address, an error will be generated and the program will stop. Of course, in a real application you'd need to provide extensive error checking. SocketWrench errors start at 24,000 and correspond to the error codes used by the Windows Sockets library. Most errors will occur when setting the host name, address, service port or Action property.

Comments

  1. 08 Jan 2005 at 15:46

    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?

  2. 10 Jul 2003 at 01:43

                    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?
                                 

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of SocketWrench Control.

Leave a comment

Sign in or Join us (it's free).

Catalyst Development

Related discussion

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...

We'd love to hear what you think! Submit ideas or give us feedback