Topic is ZModem. I have written a zmodem protocol back in VB6 days and need to convert to B4A and B4J. It was a very successful two way protocol that recovers from errors and continues without having to start a new download. ie: incomplete . I am aware that there is ftp available in b4x however zmodem over tcp connection is required.
I cannot work out how to have fixed width strings in b4x. Below is some code from vb6 to demonstrate what I require to achieve. As you will see this is set to a specific width or chunk size........
So after having our chunk size empty strings, we then pull a chunk from a file that we wish to transfer. The following VB function I wrote will retrieve the required next chunk and return the data as a string ready to poke down the tcp ip connection.
the two questions I have, is
1. How to get a fixed width string and
2. Are we able to open a file for binary random access like in the function above ?
Any help would be greatly appreciated.
I cannot work out how to have fixed width strings in b4x. Below is some code from vb6 to demonstrate what I require to achieve. As you will see this is set to a specific width or chunk size........
VB6 Global Code:
Global c2048 As String * 2048
Global c1024 As String * 1024
Global c512 As String * 512
Global c256 As String * 256
Global c128 As String * 128
Global c64 As String * 64
Global c32 As String * 32
Global c16 As String * 16
Global c8 As String * 8
Global c4 As String * 4
Global c2 As String * 2
Global c1 As String * 1
So after having our chunk size empty strings, we then pull a chunk from a file that we wish to transfer. The following VB function I wrote will retrieve the required next chunk and return the data as a string ready to poke down the tcp ip connection.
VB6 Finction Code:
Function ZModem(TheFileName As String, Record As Long) As String
Dim RecNum As Long
Dim TheFile As Integer
Dim OutString As String
Dim TotalBytes As Long
TheFile = FreeFile
Open TheFileName For Binary Shared As #TheFile
Seek TheFile, 1
CPXLen = LOF(TheFile)
TotalBytes = CPXLen
mn = 0
If CPXLen > 0 Then
RecNum = 0
Do 'While CPXLen > 0
If CPXLen >= 2048 Then
Get #1, , c2048
OutString = c2048
RecNum = RecNum + 1
CPXLen = CPXLen - 2048
mn = mn + 2048
ElseIf CPXLen >= 1024 Then
Get #1, , c1024
OutString = c1024
RecNum = RecNum + 1
CPXLen = CPXLen - 1024
mn = mn + 1024
ElseIf CPXLen >= 512 Then
Get #1, , c512
OutString = c512
RecNum = RecNum + 1
CPXLen = CPXLen - 512
mn = mn + 512
ElseIf CPXLen >= 256 Then
Get #1, , c256
OutString = c256
RecNum = RecNum + 1
CPXLen = CPXLen - 256
mn = mn + 256
ElseIf CPXLen >= 128 Then
Get #1, , c128
OutString = c128
RecNum = RecNum + 1
CPXLen = CPXLen - 128
mn = mn + 128
ElseIf CPXLen >= 64 Then
Get #1, , c64
OutString = c64
RecNum = RecNum + 1
CPXLen = CPXLen - 64
mn = mn + 64
ElseIf CPXLen >= 32 Then
Get #1, , c32
OutString = c32
RecNum = RecNum + 1
CPXLen = CPXLen - 32
mn = mn + 32
ElseIf CPXLen >= 16 Then
Get #1, , c16
OutString = c16
RecNum = RecNum + 1
CPXLen = CPXLen - 16
mn = mn + 16
ElseIf CPXLen >= 8 Then
Get #1, , c8
OutString = c8
RecNum = RecNum + 1
CPXLen = CPXLen - 8
mn = mn + 8
ElseIf CPXLen >= 4 Then
Get #1, , c4
OutString = c4
RecNum = RecNum + 1
CPXLen = CPXLen - 4
mn = mn + 4
ElseIf CPXLen >= 2 Then
Get #1, , c2
OutString = c2
RecNum = RecNum + 1
CPXLen = CPXLen - 2
mn = mn + 2
ElseIf CPXLen >= 1 Then
Get #1, , c1
OutString = c1
RecNum = RecNum + 1
CPXLen = CPXLen - 1
mn = mn + 1
End If
If CPXLen = 0 And (RecNum < Record) Then
GoTo 100
Exit Do
End If
Loop While RecNum < Record
OutString = FillIt(Format(RecNum, "0"), 1, 8) + _
FillIt(Format(TotalBytes, "0"), 1, 8) + _
OutString
Else
' OutString = FillIt(Format(RecNum, "0"), 1, 8) + OutString
100 OutString = ""
OutString = FillIt(Format(0, "0"), 1, 8) + _
FillIt(Format(TotalBytes, "0"), 1, 8) + _
OutString
End If
Close #TheFile
ZModem = OutString + CRC(OutString)
End Function
the two questions I have, is
1. How to get a fixed width string and
2. Are we able to open a file for binary random access like in the function above ?
Any help would be greatly appreciated.