Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27351

Unable to read complete data from server

$
0
0
Hi, totally new to Visual Basic programming here. I have a program (compiled from a .php script of all things) that reads a string of data from a server. This data is 106 bytes in length, starts with 0x00, 0x00, 0x42 and terminates with a CRLF (0x0D, 0x0A).

In VB I can read data from the server, but about 98% of the time I am unable to read the entire string, instead a number of bytes (random, but usually between 20 and 30) are dropped from the beginning. Very occasionally I get lucky and receive the whole string.

New data is available on the server every 8-10 seconds.

Here is a bare bones version of what I have scraped together from looking around he net, there are no error routines at present

Code:

Imports System.Net.Sockets
Imports System.IO

Module Module1
    Sub Main()
        Dim returndata As String
        Dim TcpClient As New TcpClient

        TcpClient.Connect("10.1.1.5", "1001")

        Dim netStream As NetworkStream = TcpClient.GetStream()
        Dim streamreader As New StreamReader(netStream)
        Dim bytes(TcpClient.ReceiveBufferSize) As Byte
        netStream.Read(bytes, 0, CInt(TcpClient.ReceiveBufferSize))
        returndata = streamreader.ReadLine()
        TcpClient.Close()
        netStream.Close()
    End Sub


End Module

Any pointers as to how I can read a full string every time?

Thanks,

ex-egll

Viewing all articles
Browse latest Browse all 27351

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>