sorry for my english
I need an example!
I want a server tcp asynchronous receive files larger than 8192 bytes how do I save them B4a
With two weeks and we slam head
If File.Exists(File.DirRootExternal,"String.txt") Then
File.Delete(File.DirRootExternal,"String.txt")
End If
Dim out As OutputStream
out=File.OpenOutput(File.DirRootExternal,"String.txt",True)
'out.WriteBytes(fileByte, 0, fileByte.Length)
File.Copy2(Ini,out)
out.Flush
out.Close
I try to get the file sent from the server and write it with this method, but I write only the last part
Hi,
did you check the transmitter? There must be a TCP/IP overflow on server side. I send the file in chunks,first chunk - test the receipt on the other side . send second chunk and so on. I have servers written in PHP and C# or VB.net.
Dim bytesfile() As Byte = IO.File.ReadAllBytes("E:\String1.txt") '1.jpg
SendData(bytesfile, ListBox1.SelectedItems(0).Tag)
'---send the data to the client---
Public Sub SendData(ByVal data As Byte(), ByVal client As Socket)
Try
client.BeginSend(data, 0, data.Length, SocketFlags.None, New AsyncCallback(AddressOf onsend), client)
Catch ex As Exception
MsgBox("SendData")
UpdateList(controlclientitem)
End Try
End Sub
You should always use AsyncStreams to handle the data.
If you are communicating with a VB.Net server then you cannot use prefix mode: https://www.b4x.com/android/forum/threads/7669/#content
This means that you need to manage the messages yourself. For a simple file transfer it should be simple. Just open an outputstream and write the bytes in NewData event.
If more information is sent other than the file then it becomes more complicated. Again, if you use B4J everything will be trivial and you will be able to send files of any size with 20 lines of code.
thanks erel have already used the server for my b4j Projects.
I'm helping someone who needs a server in vb.net and why I ask for help.
I get all the data but I can not write I always write the last byte I receive.