Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"this code has called into another function"

Status
Not open for further replies.

MikeWiz628

Programmer
Dec 24, 2002
22
US
I'm receiving a stream from a socket that I opened and I'm cycling until the buffer size is 0.

However I'm getting the green bar with the message "this code has called into another function".

I know the string is finished because the pipe symbol is at the end, however, I can't leave the loop.

Here's the snippet:


' Receive the TcpServer.response.
' Buffer to store the response bytes.
data = New [Byte](1024) {}

' String to store the response ASCII representation.
Dim responseData As [String] = [String].Empty

' Read the first batch of the TcpServer response bytes.
Dim bytes As Integer = stream.Read(data, 0, data.Length)

Do while bytes > 0
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
Console.WriteLine("Received: {0}", responseData)
bytes = stream.Read(data, 0, data.Length)
Loop

' Close everything.
stream.Close()
client.Close()

Any idea why it's hanging?

Thanks in advance!
 
The way I perform this is to use the .Available. The .Available will return the length of the data returned. You can loop and check if theres data in the queue and when there is, receive it into a buffer to work with. Then just loop through based on the buffer.

Code:
Dim tmpLen As Long
        Dim tmpBuf() As Byte
        Dim tmpStr As String
Do While True
    If prvTCP.Available > 0 Then
                tmpLen = prvTCP.Available
                ReDim tmpBuf(tmpLen)
                prvTCP.Receive(tmpBuf, 0, tmpLen, SocketFlags.None)
                tmpStr = System.Text.Encoding.ASCII.GetString(tmpBuf, 0, tmpLen)
                prvBuffer = tmpStr
                Do
                    tmpStr = tmpStr.Substring(0)
                While tmpStr.Length > 0

                
            End If
            Thread.Sleep(100)
Loop
 
I took some of your ideas and this is what I came up with:

' String to store the response ASCII representation.
Dim responseData As [String] = [String].Empty

'TcpServer response bytes.
Dim bytes As Integer

Do
' Read the first batch of the TcpServer response bytes.
bytes = stream.Read(data, 0, data.Length)
responseData = responseData + System.Text.Encoding.ASCII.GetString(data, 0, bytes)
System.Threading.Thread.Sleep(100)
Loop While client.Available > 0

Console.WriteLine("Received: {0}", responseData)

' Close everything.
stream.Close()
client.Close()

What do you think? With the the thread.sleep, I don't receive all of the data. I'm new to the who TCPclient and buffering scenario.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top