Results 1 to 2 of 2

Thread: Really simple sockets question.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    167

    Really simple sockets question.

    Hi . I have the following code. I want to read the entire message instead of reading it char by char. How would i do this? Im thinking along the lines of Reader.ReadToEnd(). But Im having a hard time implementing such a feature.

    Thanks

    Code:
    Imports System.Net.Sockets
    Imports System.Threading
    Imports System.IO
    Imports System.Net
    
    Class Window1
    
        Dim Listener As New TcpListener(65535)
        Dim Client As New TcpClient
        Dim Message As String = ""
    
        Private Sub StartServerButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles StartServerButton.Click
    
            Dim ListThread As New Thread(New ThreadStart(AddressOf Listening))
            ListThread.Start()
    
        End Sub
    
        Private Sub Listening()
    
            Listener.Start()
    
            While Listener.Pending = False
    
                Message = ""
                Client = Listener.AcceptTcpClient()
    
                Dim Reader As New StreamReader(Client.GetStream())
    
                While Reader.Peek > -1
                    Message = Message + Convert.ToChar(Reader.Read()).ToString
                End While
    
                MsgBox(Message, MsgBoxStyle.OkOnly)
    
            End While
    
        End Sub
    
    End Class

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Really simple sockets question.

    Search the forum for TCPClient examples, there are loads that will show you how to do what you want (specifically Athiest has written a few good ones).
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width