For client server communications I created 2 object that will hide the difficulties in the Winsock API calls for you and stimulate developing in an object oriented way. The GenericClient object can be used to create any sort of client application and the GenericServer object can be used to create any sort of server application. You will probably write your own protocol handler (like the SMTP and POP that you can find below ) using the OnDataArive event.

A demo is included that will show you how to make a simple chat application and an other demo is available that shows you how to do port mapping. If you want more samples, then have a look at the SMTP and POP library mentioned below.

Click here to download the complete source code, the compiled DLL and the demos.

Credits: The (super) SubClass code is from a publication from Paul Canton [Paul_Caton@hotmail.com].
The winsock stuff is inspired by a publication from ‘Coding Genius’.
The Exception hanler is based on a publication from Thushan Fernando.

Here is some code that will show you how to use the GenericClient object:

Private WithEvents cClient  As GenericClient
Private Sub Form_Load()
   Set cClient = New GenericClient
   cClient.Connect "ftp.microsoft.com", CLng(21)
   cClient.Connection.Send "help" & vbCrLf
End Sub

Private Sub Form_Unload(Cancel As Integer)
   cClient.Connection.CloseSocket
   Set cClient = Nothing
End Sub

Private Sub cClient_OnConnect()
   debug.print "Client connected to " & _
      cClient.Connection.GetRemoteHost & _
      "(" & cClient.Connection.GetRemoteIP & ")" & _
      " on port " & cClient.Connection.GetRemotePort
End Sub

Private Sub cClient_OnDataArrive()
Dim strData As String
   cClient.Connection.Recv strData
   debug.print strData
End Sub
Share