Android Tutorial FileTransfer - Send and receive files with AsyncStreams

Status
Not open for further replies.

androidtom

Member
Licensed User
Longtime User
When using the async stream file transfer with the UI in the activity and a separate service module (FileTransfer.bas) handling the network read/writes, what's the "correct way" to notify the activity that a file has been received completely? I can set a flag in AStream_NewStream event and then monitor that flag with a timer in the activity but that seems more like a hack than a clean method. Is there a more acceptable approach to monitoring completion of a service?
 

androidtom

Member
Licensed User
Longtime User
You can use CallSub or CallSubDelayed to send a message from the service to the activity.
Thank you Erel! CallSubDelayed seems much better to me than monitoring a flag with a timer to detect completion by a service.
 

janderkan

Well-Known Member
Licensed User
Longtime User
Hi
I have read this code and the .net filetransfer code.
If I stick to using the .write method, in .net I will receive 4 bytes with the length and then the data.
Is the length of data only limited to length set by the 4 bytes?

Jan
 

tdocs2

Well-Known Member
Licensed User
Longtime User
@Erel,

The File Transfer is indeed a wonderful application. I have modified it (to just use WiFi and display more user information and also incorporated the code into my app to transfer files between devices running my app.

I am very grateful to you for this app.

The BIG question is:

Is there a B4J version of this app? If there is, I plan to incorporate it into a B4J app I am planning.

Thank you.

Sandy
 

LucaMs

Expert
Licensed User
Longtime User


I could be wrong (EVEN because I'm not Erel ) but since there is the b4j library JRandomAccessFile, make this version should not be very difficult.
But in this case, why Erel has made the PC side sw using C #? Perhaps because at the time jRandomAccessFile not yet exist.
 

AscySoft

Active Member
Licensed User
Longtime User
Hi.
I am trying to implement this thing in my app. I was able to connect from my windows pc to android phone/ copy file etc.
But when I try the other way around, from Android - File Transfer app to windows pc, when i hit the Connect WiFi button, connection fails.
First with the following message "(ErrnoException) libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)";
Then after I deactivate my firewall and antivirus, with this message: "(SocketTimeoutException) java.net.SocketTimeoutException: failed to connect to /192.168.0.47 (port 21341) after 30000ms"
PS: my windows PC lan ip is 192.168.0.47
 

AscySoft

Active Member
Licensed User
Longtime User
Windows firewall blocks incoming connections. You must add a rule to open the port.

What are you running on the PC?

Are you running the C# implementation?

I deactivate all firewalls, both from windows (8.1) and from KIS. Optionally I did create a rule in windows firewall not to block incoming activity on port 21341. None of this helped. And yes, I am running your c# example app. With it, connection from PC to Android is possible, but as describe above, not vice-versa.
Could someone confirm that connection from android 2 pc is working as expected?
 

AscySoft

Active Member
Licensed User
Longtime User
I see. So this was the problem. I don't have Visual Studio on my PC so I was not able to tell this. Is there a link in this forum that might help in creating a server "missing" part from your c# example? This forum is too big! (or I am so lazy!)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…