Public Class frmMain Inherits System.Windows.Forms.Form Dim sPage As String Dim WithEvents wsTCP As New OSWINSCK.Winsock #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents txtURL As System.Windows.Forms.TextBox Friend WithEvents txtSource As System.Windows.Forms.TextBox Friend WithEvents cmdView As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.txtURL = New System.Windows.Forms.TextBox Me.txtSource = New System.Windows.Forms.TextBox Me.cmdView = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Location = New System.Drawing.Point(8, 10) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(27, 16) Me.Label1.TabIndex = 0 Me.Label1.Text = "URL" ' 'txtURL ' Me.txtURL.Location = New System.Drawing.Point(40, 8) Me.txtURL.Name = "txtURL" Me.txtURL.Size = New System.Drawing.Size(248, 20) Me.txtURL.TabIndex = 1 Me.txtURL.Text = "http://localhost" ' 'txtSource ' Me.txtSource.Location = New System.Drawing.Point(8, 40) Me.txtSource.Multiline = True Me.txtSource.Name = "txtSource" Me.txtSource.ScrollBars = System.Windows.Forms.ScrollBars.Both Me.txtSource.Size = New System.Drawing.Size(344, 184) Me.txtSource.TabIndex = 2 Me.txtSource.Text = "" ' 'cmdView ' Me.cmdView.Location = New System.Drawing.Point(296, 8) Me.cmdView.Name = "cmdView" Me.cmdView.Size = New System.Drawing.Size(56, 20) Me.cmdView.TabIndex = 3 Me.cmdView.Text = "View" ' 'frmMain ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(360, 229) Me.Controls.Add(Me.cmdView) Me.Controls.Add(Me.txtSource) Me.Controls.Add(Me.txtURL) Me.Controls.Add(Me.Label1) Me.Name = "frmMain" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Test OstroSoft Winsock Component" Me.ResumeLayout(False) End Sub #End Region Private Sub cmdView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdView.Click 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)) Exit Sub ErrHandler: MsgBox("Error " & Err.Number & ": " & Err.Description) End Sub Private Sub wsTCP_OnClose() Handles wsTCP.OnClose wsTCP.CloseWinsock() 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 MsgBox(Number & ": " & Description) End Sub Private Sub wsTCP_OnStatusChanged(ByVal Status As String) Handles wsTCP.OnStatusChanged Console.WriteLine(Status) End Sub Private Sub txtSource_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSource.TextChanged End Sub Private Sub txtURL_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtURL.TextChanged End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub End Class