| Winsock & SSL without the Winsock control |
Applies To |
|
| OS: VB: |
NT, 9x, 2000 5, 6 |
|
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:
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)