logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 Winsock and SSL without the Winsock control

Posted on
5/17/2003
Author:
Brian Yule
Email:
Not Shown
Applies To OS:
NT, 9x, 2000
Product:
5, 6



Updated on March 03, 2004
By Brian Yule (byule at PembrokeTechnology.com)
Download the project (117 kb)

This is another windows socket that doesn't use the winsock.ocx file. It was created to remove the dependency on the winsock.ocx file. The feature that separates this implementation from others is an SSL class that encrypts information as it is sent over the wires. In addition, the implementation has the following features:

  1. Ping Capability through ICMP
  2. Trace Route, also known as TRACERT
  3. Includes most of the options for Socket, IRDA, IP, IPV6, Multicasting, IPX/SPX, UDP and TPC.
  4. Listens and accepts connections
  5. It uses call backs to return the socket events.
  6. It accesses the low level Winsock API.
  7. It has a BYTEINPUTSTREAM class for buffering the input.
  8. It has a Control class for sending unencrypted data across the network.
  9. It has a SSL class for sending encrypted data across the network.
The SSL class can be used for getting HTML files over HTTPS.

Getting encrypted information is as easy as calling the Connect method (to connect to the website), and then calling SendData with the URL you want to download. The SSL class reports various events via the WithEvents interface, so that you know when the connection has been made (or broken) and act on that information.

It is currently being used to run VOIP client with less than 2% of the CPU. It has many of the functions that neither Winsock.OCX and dsSockets.OCX don't. The included project has a quick and dirty examples for Ping, Trace Route, Connecting and retrieving an SSL page.

Add the following code to form
Private WithEvents trcRouter As BX_WSA.traceRoot
Private WithEvents Pinger As BX_WSA.Ping
Private WithEvents oSSLControl As BX_WSA.SSLControl

Private Sub btnConnectSSL_Click()
    txtResult.Text = "Connecting..."
    
    If oSSLControl.Connect(txtSSLAddress.Text, 443) = -1 Then txtResult.Text = "Connect Failed"
End Sub

Private Sub btnGetHtmlViaSSL_Click()
    txtResult.Text = ""
    Call oSSLControl.SendData("GET https://" & txtSSLAddress.Text & "/" & vbCrLf)
End Sub

Private Sub btnPing_Click()
    Dim i As Byte
    Dim sIpAddress As String
    
    If SocketsInitialize() Then
    
        'pass the host address to the function
        sIpAddress = GetIPFromHostName(txtAddress.Text)
        SocketsCleanup   
    Else
        MsgBox "Windows Sockets for 32 bit Windows " & _
                "is not successfully responding."
              
        Exit Sub
    End If
    
    
    txtResult.Text = "Ping " & txtAddress.Text & " (ip=" & sIpAddress & ")"
    DoEvents
    For i = 1 To 4
        Call Pinger.vbIcmpSendEcho(IPAddress:=sIpAddress, TIMEOUT:=2000)
        DoEvents
    Next i
    txtResult.Text = txtResult.Text & vbCrLf & "Ping Complete"

End Sub

Private Sub btnTraceRt_Click()
    txtResult.Text = "Trace route to " & txtAddress.Text
    DoEvents
    Call trcRouter.TraceRT(txtAddress.Text)
End Sub

Private Sub Command1_Click()
    txtResult.Text = "Trace route to " & Text2.Text
    DoEvents
    Call trcRouter.TraceRT(Text2.Text)

End Sub

Private Sub Form_Load()
    Set trcRouter = New BX_WSA.traceRoot
    Set Pinger = New BX_WSA.Ping
    Set oSSLControl = New BX_WSA.SSLControl
    
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set trcRouter = Nothing
    Set Pinger = Nothing
    Set oSSLControl = Nothing
End Sub

Private Sub oSSLControl_Closed(ByVal lngSockId As Long)
    txtResult.Text = txtResult.Text & vbCrLf & "Closed"
    btnGetHtmlViaSSL.Enabled = False
End Sub

Private Sub oSSLControl_Connected(ByVal lngSockId As Long)
    txtResult.Text = txtResult.Text & vbCrLf & "Connected"
    btnGetHtmlViaSSL.Enabled = True
End Sub

Private Sub oSSLControl_LayerChange(NewLayer As Integer)
    txtResult.Text = txtResult.Text & vbCrLf & "LayerChange: " & NewLayer
End Sub

Private Sub oSSLControl_Received(ByVal lngSockId As Long, ByVal strRetVal As String)
    txtResult.Text = txtResult.Text & vbCrLf & "Received"
    txtResult.Text = txtResult.Text & strRetVal
End Sub

Private Sub oSSLControl_SendReady(ByVal lngSockId As Long)
    txtResult.Text = txtResult.Text & vbCrLf & "SendReady"
End Sub

Private Sub Pinger_Finished(Message As String)
    txtResult.Text = txtResult.Text & vbCrLf & Message
End Sub

Private Sub Pinger_HopInfo(Message As String)
    txtResult.Text = txtResult.Text & vbCrLf & Message
End Sub

Private Sub trcRouter_Finished(Message As String)
    txtResult.Text = txtResult.Text & vbCrLf & Message
End Sub

Private Sub trcRouter_HopInfo(Message As String)
    txtResult.Text = txtResult.Text & vbCrLf & Message
End Sub
Download the project (117 kb)

Note that this download contains multiple projects: The Winsock Implementation, Subclassing implementation and a test project. To run everything at once, unzip the project, double-click on g.vbg and run.




Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By Anonymous. Posted on 2/20/2006 6:04:39 AM
this is awesome.

#2. By Anonymous. Posted on 2/20/2006 6:41:39 AM
How can I do the 'whoami' command using this technique?

#3. By Anonymous. Posted on 2/20/2006 6:46:02 AM
Oh, sorry, I didn't read the article in full.

#4. By Anonymous. Posted on 2/20/2006 6:52:47 AM
Ok, I'll go quietly now.

#5. By Anonymous. Posted on 3/22/2006 12:22:20 AM
Note: this superlib doesn't take care of your customers!

#6. By Jerome. Posted on 3/31/2006 4:18:21 AM
Wow. Incredible. What a masterpiece of elegant design and consummate craftsmanship. Thank you. I only wish I knew where to begin reading this gem.

#7. By Ruvenss. Posted on 5/10/2006 3:32:07 PM
I will use this code for MySXP Project, as the others said is a real masterpiece, I will also add the credits using this website as reference

#8. By lyn. Posted on 7/27/2006 11:30:17 PM
Can you point me in the direction of some more examples. I'd like to use the above code to connect to a socket on an ip, fire it some data and then check the reply. Also have another program listening on a socket recieve the data and respond in a particular way. Its to check that some systems that I control are actualy live (I use the ping which works fantastic but this only lets me know the router is OK).
Apreciate any guidance.

#9. By Anonymous. Posted on 9/27/2006 6:59:25 AM
Absolutely the coolest. Much thanks.

#10. By Lion. Posted on 10/24/2007 9:06:50 PM
CAN SOMEONE SEND ME THE SOURCE ITS VERY IMPORTEND!!!
255-539-405 ord email lion_nagenrauft@web.de
CAN SOMEONE SEND ME THE SOURCE ITS VERY IMPORTEND!!!
255-539-405 ord email lion_nagenrauft@web.de
CAN SOMEONE SEND ME THE SOURCE ITS VERY IMPORTEND!!!
255-539-405 ord email lion_nagenrauft@web.de
CAN SOMEONE SEND ME THE SOURCE ITS VERY IMPORTEND!!!
255-539-405 ord email lion_nagenrauft@web.de
CAN SOMEONE SEND ME THE SOURCE ITS VERY IMPORTEND!!!

#11. By Patrice. Posted on 11/14/2007 1:05:04 PM
Will somebody hve sample of a server using this lib

#12. By Anonymous. Posted on 2/6/2008 4:23:04 PM
Lame, really lame

#13. By Ken. Posted on 8/10/2008 6:11:34 PM
Please come

#14. By chris. Posted on 11/28/2008 1:44:19 AM
i like it.

#15. By Andrea. Posted on 1/11/2009 1:32:20 AM
hello, i downloaded the code and i tryed it but it doesn't work.
I'd like to get pages using https://

after clicked on the button, the program wait infinitely
leaving blank the text box.
anyone knows the reason?

regards,
andrea

#16. By GioRock. Posted on 5/12/2012 11:47:37 PM
Hey, I solved problem with servers using RSAv3 certificate during handshake keys exchange, if someone want to know how to apply this modify, contact-me at my email address...

Good piece of code both of your libraries...