Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

vb.net - tcpclient.networkstream help

Options
  • 09-12-2008 11:58pm
    #1
    Registered Users Posts: 938 ✭✭✭


    I'm trying to read data, send data, read data again from telnet session. The first reading comes in ok but the second doesn't. I can't seem to see what I'm doing wrong. I'm just learning this stuff btw,
    
            Dim tcpClient As New System.Net.Sockets.TcpClient()
            tcpClient.Connect(txtip.Text, txtport.Text)
            Dim networkStream As System.Net.Sockets.NetworkStream = tcpClient.GetStream()
            If networkStream.CanWrite And networkStream.CanRead Then
    
                Dim bytes(tcpClient.ReceiveBufferSize) As Byte
                Dim sendBytes As [Byte]()
                Dim returndata As String = ""
    
                '***read the data from the server in to the string returndata
                networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
                returndata = System.Text.Encoding.ASCII.GetString(bytes)
    
    
                networkStream.Flush() '***clear off the current data
    
                '***send data "admin" to the server
                sendBytes = System.Text.Encoding.ASCII.GetBytes("admin")
                networkStream.Write(sendBytes, 0, sendBytes.Length)
    
                networkStream.Flush() '***clear off the current data
    
                '***read the data from the server in to the string returndata
                networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
                returndata = System.Text.Encoding.ASCII.GetString(bytes)
    


Advertisement