So I have the code below in an app I am working on. The code is called after having made a connection to a TCP server. The intention is for it to read a file and send one line at a time to the server, wait for a response then increment one of two variables based on the response then continue to send the next line until it reaches the end of file.
The code is connecting, reads the first line from the file, sends it and gets the proper response. Stepping through the code in debug mode I can see that it executes the line intGood=intGood+1 but then it jumps to the IP.Close statement near the bottom.
Any idea why this would be happening?
The code is connecting, reads the first line from the file, sends it and gets the proper response. Stepping through the code in debug mode I can see that it executes the line intGood=intGood+1 but then it jumps to the IP.Close statement near the bottom.
Any idea why this would be happening?
B4X:
Sub UploadData() As Boolean
If File.Exists(File.DirDefaultExternal,"Data.txt") Then
Dim sReader As TextReader,sRecord As String
Dim IPReader As TextReader,IPWriter As TextWriter
Dim IntGood As Int, intBad As Int
Dim fTotal As Long,fProcessed As Long
fTotal=File.Size(File.DirDefaultExternal,"Data.txt")
IPReader.Initialize(IP.InputStream)
IPWriter.Initialize(IP.OutputStream)
ProgressBar1.Progress=0
sReader.Initialize(File.OpenInput(File.DirDefaultExternal,"Data.txt"))
Do While sReader.Ready
sRecord=sReader.readline
If sRecord.Length>1 Then
fProcessed=fProcessed+sRecord.Length
ProgressBar1.Progress=Round(fProcessed/fTotal*100)
IPWriter.WriteLine(sRecord)
IPWriter.Flush
sRecord=IPReader.readline
If sRecord.StartsWith("OK") Then
IntGood=IntGood+1 ' Executes this line then jumps to IP.Close
Else
intBad=intBad+1
End If
Else
Exit
End If
Loop
sReader.close
End If
IP.close ' Jumps here after the OK response??
Return True
End Sub