Master Zero
Well-known member
- Joined
- Sep 10, 2005
- Messages
- 51
- Programming Experience
- Beginner
Hello, 
I am having some problems that I really need help on. I created a class that can retrieve a webpage. Actually there are two functions, one which brings back the web page and another that just process the URL to send info to a waiting CGI program written in php, using the GetReponse() method.
For some reason or another, I can’t seem to understand or track down why it stops after 3 calls. I will post the software code and class below:
Any and all help received is greatly appreciated.
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
		
			
		
		
	
				
			I am having some problems that I really need help on. I created a class that can retrieve a webpage. Actually there are two functions, one which brings back the web page and another that just process the URL to send info to a waiting CGI program written in php, using the GetReponse() method.
For some reason or another, I can’t seem to understand or track down why it stops after 3 calls. I will post the software code and class below:
Any and all help received is greatly appreciated.
			
				VB.NET:
			
		
		
		Module Module1
    Dim WithEvents webClient As New WebCommunicator
    Sub Main()
        Dim line As String = ""
        Dim t As New Threading.Thread(AddressOf Listen)
        t.Start()
        line = Console.ReadLine
        While (line <> "exit")
            webClient.getPage(_SITE + "php/chat/SetMessage.php?computer_name=" + _
                My.Computer.Name + "&iam=server&message=" + line.Trim, False)
            line = Console.ReadLine
        End While
    End Sub
    Private Sub Listen()
        webClient.getPage(_SITE + "php/chat/GetMessage.php?computer_name=" + _
            My.Computer.Name + "&iam=server", True)
        Dim t As New Threading.Thread(AddressOf Listen)
        t.Start()
    End Sub
    Private Sub webClient_GotError(ByVal message As String) Handles webClient.GotError
        Console.WriteLine("****** Error: " + message)
    End Sub
    Private Sub webClient_GotPage(ByVal source As String) Handles webClient.GotPage
        If source.Substring(0, 4) = "NULL" Then
        Else
            Console.WriteLine(source.Substring(0, source.Length - 168))
        End If
    End Sub
End Module
			
				VB.NET:
			
		
		
		Public Class WebCommunicator
    Public Event GotPage(ByVal source As String)
    Public Event GotError(ByVal message As String)
    Private myWebStream As IO.StreamReader
    Private myWebRequest As Net.HttpWebRequest
    Public Sub getPage(ByVal url As String, Optional ByVal pageSource As Boolean = True)
        Try
            If pageSource = False Then
                Me.PageWithOutSource(url)
            Else
                RaiseEvent GotPage(Me.PageSource(url))
            End If
        Catch ex As Exception
            RaiseEvent GotError(ex.Message)
        End Try
    End Sub
    Private Function PageSource(ByVal url As String)
        Me.myWebRequest = Net.HttpWebRequest.Create(url)
        Me.myWebStream = New IO.StreamReader(Me.myWebRequest.GetResponse.GetResponseStream)
        Return Me.myWebStream.ReadToEnd.Trim
    End Function
    Private Sub PageWithOutSource(ByVal url As String)
        Me.myWebRequest = Net.HttpWebRequest.Create(url)
        Me.myWebRequest.GetResponse()
    End Sub
End Class 
	 
 
		 
 
		 
 
		 
 
		 
 
		