Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• About the product
• Download
• Sample projects:
Using with Visual Basic
Using with VB.NET
Using with C#
Using with ASP
Using with ASP.NET
Using with Office (VBA)
Using with VBScript
Using with JavaScript
Using with SQL Server
• Support Forum
Winsock Component - Using with ASP.NET

Retrieving web page source, using OstroSoft Winsock Component (oswinsck.dll)
Download project source code

Minimum requirements: ASP.NET, oswinsck.dll*
* If you don't have OstroSoft Winsock Component, see installation instructions

1. In Visual Studio.NET create new Visual Basic ASP.NET Application.
2. Click on Project menu and select "Add Reference".
3. In "Add Reference" dialog box click on COM tab and select OSWinsck. Click OK to save a new reference.
4. Enter the following code:

Public Class WebForm1
  Inherits System.Web.UI.Page

  Dim sPage As String
  Dim WithEvents wsTCP As New OSWINSCK.Winsock
  Dim bClose As Boolean = False
  Dim bError As Boolean = False

#Region " Web Form Designer Generated Code "

  Private Sub Page_Load(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here    
    If IsPostBack Then
      On Error GoTo ErrHandler
      Dim sServer As String
      Dim nPort As Long

      nPort = 80
      sServer = Trim(txtURL.Text)
      If InStr(sServer, "://") > 0 Then _
        sServer = Mid(sServer, InStr(sServer, "://") + 3)
      If InStr(sServer, "/") > 0 Then
        sPage = Mid(sServer, InStr(sServer, "/") + 1)
        sServer = Strings.Left(sServer, InStr(sServer, "/") - 1)
      End If
      If InStr(sServer, ":") > 0 Then
        nPort = Mid(sServer, InStr(sServer, ":") + 1)
        sServer = Strings.Left(sServer, InStr(sServer, ":") - 1)
      End If
      If sServer = "" Then Err.Raise(12001, , "Invalid URL")

      wsTCP.Connect(sServer, CInt(nPort))
      Do While Not (bClose Or bError)
        System.Threading.Thread.Sleep(10)
      Loop
      Exit Sub

ErrHandler:
      txtSource.Text = "Error " & Err.Number & ": " & Err.Description
    End If
  End Sub

  Private Sub wsTCP_OnClose() Handles wsTCP.OnClose
    wsTCP.CloseWinsock()
    bClose = True
  End Sub

  Private Sub wsTCP_OnConnect() Handles wsTCP.OnConnect
    wsTCP.SendData("GET /" & sPage & " HTTP/1.0" & vbCrLf & vbCrLf)
  End Sub

  Private Sub wsTCP_OnDataArrival(ByVal bytesTotal As Integer) _
      Handles wsTCP.OnDataArrival
    Dim sBuffer As String
    wsTCP.GetData(sBuffer)
    txtSource.Text = txtSource.Text & sBuffer
  End Sub

  Private Sub wsTCP_OnError(ByVal Number As Short, _
      ByRef Description As String, ByVal Scode As Integer, _
      ByVal Source As String, ByVal HelpFile As String, _
      ByVal HelpContext As Integer, ByRef CancelDisplay As Boolean) _
      Handles wsTCP.OnError
    txtSource.Text = "Error " & Number & ": " & Description
    bError = True
  End Sub

  Private Sub wsTCP_OnStatusChanged(ByVal Status As String) _
      Handles wsTCP.OnStatusChanged
    Console.WriteLine(Status)
  End Sub
End Class

Copyright © 1996-2008 OstroSoft. All rights reserved. info@ostrosoft.com