Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

vb.net - tcpclient.networkstream help

  • 09-12-2008 11:58PM
    #1
    Registered Users, Registered Users 2 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