Dim bc As ByteConverter
bc.LittleEndian=True
Dim Buffer (65535) As Byte, Read As Int
Try
Dim inStream As InputStream=client.InputStream
Dim count As Int
Dim LengthBytes(4) As Byte,Length As Int
count=inStream.ReadBytes (LengthBytes,0,4)
If count=-1 Then Return True
Length =bc.IntsFromBytes(LengthBytes)(0)
Dim TypeB(1) As Byte
inStream.ReadBytes (TypeB,0,1)
Select Case TypeB(0)
Case 67'Command
Dim CommandBytes(Length-1) As Byte
inStream.ReadBytes (CommandBytes,0,Length-1)
Dim nCommandData As String=BytesToString(CommandBytes , 0, Length-1,"utf8")
ProcessCommand(nCommandData)
Case 70'File
'------------- Read FileName -------------
Dim FileNameBytes(Length-1) As Byte
inStream.ReadBytes (FileNameBytes,0,Length-1)
currentFile= BytesToString(FileNameBytes , 0, Length-1,"utf8")
'-----------------------------------------
'------------ Read File Length as long 8 bytes
Dim FileLengthBytes(8) As Byte
inStream.ReadBytes (FileLengthBytes,0,8)
Dim FileLength As Long =bc.LongsFromBytes(FileLengthBytes)(0)
Dim outFile As OutputStream = File.OpenOutput(MainHelper.ActiveOfflineDirectory, currentFile, True)
'------------ Read File Data -------------
'-------- Write File Data
Do While Read < FileLength
count=inStream.ReadBytes(Buffer,0,Min((FileLength-Read),Buffer.Length ))
'Write To File
outFile.WriteBytes(Buffer, 0, count)
'Increment CRC32
progressValue = 100 * Read / FileLength
UpdateProgress(False)
Read=Read+count
DoEvents
Loop
Dim ChecksumBytes (8) As Byte
inStream.ReadBytes(ChecksumBytes,0,8)
outFile.Close
End Select
Catch
Log(LastException)
ConnectSocket
End Try
Return False