SocketWrench Control

Closing the Connection

Finally, when the client closes the connection, the socket control must also close it's end of the connection. This is accomplished by adding a line of code in the socket's Disconnect event:

Sub Socket2_Disconnect (Index As Integer)

Socket2(Index).Action = SOCKET_CLOSE

End Sub

To make sure that all of the socket connections are closed when the application is terminated, the following code should be included in the form's Unload event:

Sub Form_Unload (Cancel As Integer)

Dim I As Integer
If Socket1.Connected Then

Socket1.Action = SOCKET_CLOSE

End If
If Socket2(0).Listening Then

Socket2(0).Action = SOCKET_CLOSE

End If

For I = 1 To LastSocket

If Socket2(I).Connected Then

Socket2(I).Action = SOCKET_CLOSE

End If

Next I
End

End Sub

The only new property shown here is the Listening property, which like the Connected property, is a Boolean flag. If the control is listening for incoming connections, this property will return True, otherwise it returns False. This is added only as an extra "sanity check", and the property should always return True for this instance of the control.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Before software should be reusable, it should be usable.” - Ralph Johnson