Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Tcp reading while loop not stopping

So what my problem is that I have a tcp application, sending a file (in bytes) to my current application, witch (for now) is just supposed to check if the bytes sendt are equal to the bytes recieved. (Sending and reciving in the same application).
PHP Code

<?php 
Sub Read
()
        
a("Initialized reading")
        
Dim Byts2 As New List(Of Byte)
        
a("Vars ok")
        
' Try
        Dim FileStr As NetworkStream = SockTcp.GetStream
        Dim NBR As Integer = 0
        Do
            Dim Temp(SockTcp.ReceiveBufferSize) As Byte
            NBR = SockTcp.Client.Receive(Temp, 0, Temp.Length, SocketFlags.None)
            Byts2.AddRange(Temp)
            a("Recived " & NBR)
        Loop While NBR > 0
        '
FileStr.Close()
        
'FileStr.Dispose()
        '
Loop
        
' Catch ex As Exception
        '
a("Ex: " & ex.Message)
        
'   End Try
        a("Done looping #2")
        a("Size of 1 was " & Byts.Length)
        a("Size of 2 was " & Byts2.Count)
        If Byts Is Byts2.ToArray Then
            a("Sucess")
        Else
            a("Error, not equal")
        End If
        File.WriteAllBytes("C:\Fraps\test.txt", Byts2.ToArray)
    End Sub 
Now my problem is that the while loop does not appear to stop, but when I check the debug log it does not appear to continue ether. As the application prints "Recieved & Number of bytes recived" every frame, nor does it print what's after the while loop.
I'v also tried various loops, they all appear to be stuck.

Debug log:
PHP Code

<?php 
Sendt data
Initialized reading
Vars ok
Recived 8193
Recived 8193
Recived 8193
Recived 8193
Recived 8193
Recived 8193
Recived 8193
Recived 8193
Recived 3248 
It sucessfully shows the "Recieved xxxx" untill X (NBR) number of bytes is 0, but is does not print what it's supposed to print right after the while loop.

also the sub "a" is just a basic print sub, think of it as Print("Text")

Thanks for any help! (in advance :D)
[Image: WMwSRhx.gif]
computer print what u tell him to
a("Vars ok")
...
a("Recived " & NBR)
What? I dont think you understood my problem. If you look at the code, after the while loop It's supposed to print a("Done looping #2"), it does not print this though, and it seems like the while loop has stopped, or else it would be spamming a("Received" & NBR). My problem is that the sub seems to stop on the while loop, it does not continue on the code after the while loop.
[Image: WMwSRhx.gif]
(Oct 23, 2013 09:27 AM)sanderele1 Wrote:  What? I dont think you understood my problem. If you look at the code, after the while loop It's supposed to print a("Done looping #2"), it does not print this though, and it seems like the while loop has stopped, or else it would be spamming a("Received" & NBR). My problem is that the sub seems to stop on the while loop, it does not continue on the code after the while loop.

I usually use 2 tcp connections for data transfer, one to tell the client or server "Its coming..." and in this info header, i keep the total length, filename, crc32 and such, so the receiver end knows when all is done.
i understood it ! the others print is after > Loop While NBR > 0
and u dont get it means its > 0
Indeed,I'v tried that. But the problem isn't the Tcp part of it (The file is just to simulate a bunch of bytes). As of the while loop does seem to be stuck. Anyways thanks for your help. .D
-
Only3, indeed I thought the same thing!, but then the debug menu should be full of "Recieved X", and since it's not it must have stopped or gotten stuck? It seems to be stuck between "Receive" and "Done Looping #2"
[Image: WMwSRhx.gif]
(Oct 23, 2013 09:46 AM)TheBarret Wrote:  I usually use 2 tcp connections for data transfer, one to tell the client or server "Its coming..." and in this info header, i keep the total length, filename, crc32 and such, so the receiver end knows when all is done.

So you provide data that a TCP frame already encapsulates in the first place? Redundant.

To OP, it is most likely your receive timeout. If it is set to infinite, or a higher number, it is going to hang the loop until another packet is received. Set the timeout to something like 3-5s and after nothing comes in it should exit your loop.
Thank you, I'll try it .D -Character limit-
[Image: WMwSRhx.gif]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by VUEDUEMay 27, 2021 05:14 AM 5 209 May 27, 2021 05:14 AM
Last Post: Shadow_Cloud
[Java] by Juice.Aug 1, 2020 08:17 PM 3 146 Aug 1, 2020 08:17 PM
Last Post: knox
[Java] by ohxerxeFeb 4, 2018 03:26 PM 3 302 Feb 4, 2018 03:26 PM
Last Post: matt