Android Question server to client B4a receive files larger than 8192 bytes

Spinter

Active Member
Licensed User
Longtime User
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
 

Spinter

Active Member
Licensed User
Longtime User
B4X:
     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
 
Last edited:
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
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.
 
Upvote 0

Spinter

Active Member
Licensed User
Longtime User
my server written VB.net

B4X:
 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
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I recommend you to use B4J to implement the server. It will make it trivial to send files of any size.

Two examples:
https://www.b4x.com/android/forum/t...ceive-objects-over-the-network.34612/#content
https://www.b4x.com/android/forum/threads/37201/#content

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.
 
Upvote 0

Spinter

Active Member
Licensed User
Longtime User
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.
 
Upvote 0
Top