Android Tutorial .Net FileTransfer - Implement AsyncStreams Prefix mode

Erel

Administrator
Staff member
Licensed User
The attached C# project, implements the new stream protocol of AsyncStreams.
Relevant tutorials:
AsyncStreams Tutorial
FileTransfer - Send and receive files with AsyncStreams

This project allows you to connect the desktop to the FileTransfer app:





Note that the desktop doesn't open a server. So it can only connect to the device.

The SharpZipLib library, which is included in the zip file, is required for the checksum calculation.

There is a single change that needs to be done in device FileTransfer app:
AsyncStreams should use little endian instead of big endian. This is done by setting the second parameter of astream.InitializePrefix to False (Sub StartAStream).

The C# source code and executable are attached.
 

Attachments

Gnappos

Member
Licensed User
FileTransfer the Desktop app: It is very interesting, you might have an update so that it functions also as a SERVER? I think this is very useful for many people.
thanks
 

Erel

Administrator
Staff member
Licensed User
The purpose of this code is to demonstrate how to implement the "AsyncStream prefix streaming" mode in .Net. It shouldn't be difficult to include this code in any type of .Net application.
 

ComposerB4A

Member
Licensed User
Hi, one question please, ¿this example works for Wifi and/or "Internet Móvil"? ¿The IP in "Internet Móvil" is Variable/Changing?
 

Erel

Administrator
Staff member
Licensed User
You should start a new project and add Form1 code. Or just open it with a text editor and copy the relevant code.
 

pauleffect

Member
Licensed User
For anyone interested:
File -> New -> Project from existing code, select the folder where you saved these files, done.

If you dont have project from existing code (as was in my case) read this.
PS: don't forget to PROJECT -> Add reference : browse for ICsharp(...).zip.dll

@Erel Thank you! If you ever find yourself in Romania, beers on me!
I apologize for not thinking about it. I mean... it's lame. I've deleted my pointless post here! keep this one though!
 
Last edited:

Erel

Administrator
Staff member
Licensed User
Test it with the executable included in the demo. If it works properly then the problem is in your implementation.
 

Yafuhenk

Active Member
Licensed User
Hi thanks for the .NET code. My goal is to send sqlite database to my Android device.
However I am facing a problem. A soon as I send a file, my Android device disconnects.
Could it be that this program only works with the latest B4A version?
This is what I am using
B4A version 3.0
B4A Library versions: Network 1.25, RandomAccessFile 2.00
B4A Demo program File Transfer
PC the attached FileTransfer.exe
Thanks for any suggestion

Henk
 

Attachments

Erel

Administrator
Staff member
Licensed User
What happens on the Android side? Are there any error messages?
 

Yafuhenk

Active Member
Licensed User
Hi Erel,

Thanks for your reply.
Yes there is an error message on the Android side.
Error: (RuntimeException) java.lang.RuntimeException: Message size too large. Prefix mode can only work if both sides of the connection follow the 'prefix' protocol.
See also the log file below.

B4X:
** Activity (main) Resume **
StartAStream
Error: (RuntimeException) java.lang.RuntimeException: Message size too large. Prefix mode can only work if both sides of the connection follow the 'prefix' protocol.
** Activity (main) Pause, UserClosed = false **
 

Yafuhenk

Active Member
Licensed User
Hi Erel. I did not change the pc app in anyway. There is an exe file attached which I used.

The example you are referring too I already tested and it works fine. The desktop app is however is written in B4J when I remember correctly. I have to implement the feature in a vb.net application. That is the reason that i was so happy finding this c# .net version. Coverting it to vb.net was easy. But as i said i didn't test this vb.net version i tested the already existing and to the forum attached exe file
 

Erel

Administrator
Staff member
Licensed User
Have you seen the message about the endianess at the end of the first post?
 

Yafuhenk

Active Member
Licensed User
Hi Erel,

That did it! Thanks!


For anyone who is interested in the vb.net FileTransfer solution here it is.
Regarding the Android side don't make the same mistake as I did.
As Erel pointed out: read the first post.

B4X:
There is a single change that needs to be done in device FileTransfer app:
AsyncStreams should use little endian instead of big endian. This is done by setting the second parameter of astream.InitializePrefix to False (Sub StartAStream).
 

Attachments

code4fun

Member
Licensed User
Could the server code be in python running on a linux machine? Has anyone tried converting the code to the python equivalent?
 
Top