Android Question Asyncstream Problems

androb

Member
Licensed User
Longtime User
Hello

I have been stuck on this issue for two days now. I hope one of you clever people can help!

I am trying to use Asyncstreams in b4a with a server written in c# (based on the example code). My aim is to have an app on the android device that takes an image and then sends it to the PC to be displayed.

I have the b4a app connecting to PC successfully, but the file fails to be recieved on the PC.

I thought this might be my implementation, so I went back to the file transfer example, and the c# desktop example posted. To my surprise this fails in the same way.

What happens is this:

I put the IP address of my Nexus 4 in the desktop transfer app, click connect and "Connected" shows on the Nexus 4.

I then click on the "Choose file" on the nexus4 filetransfer app, (which had another bug, the content chooser was returning a blank name, so I hard coded it to always send an existing image). The counter displays the correct filesize and image name on the phone, and appears to send. On the PC c# file transfer app, I get nothing. No errors, no messages. No file seems to be created on the PC, so I can only assume it is not sending the data from the b4a filetransfer app.

If i forcefully close the b4a filetransfer app, the client c# app log window says this:

Receiving: testpic.jpg���� <----- those weird chars actually show up like that
Unable to read beyond the end of the stream.

Can anyone give any advice on what the problem might be? it almost seems like the data is buffered until I forcefully close the socket and then it wakes up.

I have another related question and that is, when you use writestream to send a block of data, will it just keep trying to send all of it (say its a 25MB file) Or is there some limit on the amount of data that can be sent in one "chunk"? - does TCP take care of "chunking" ?
 

androb

Member
Licensed User
Longtime User
Hello

I have tried this application. I can connect to the nexus4 with it, but when I try to draw and send an image from PC to device or click on any of the "Send" buttons in AsyncStreamsObject Example, the file transfer app on the device is force closed. If I click on "choose file" on the filetransfer app on the phone, and select a file, the b4j app crashes.

The log windows in b4j shows:

Program started.
(TextField) TextField[id=txtIP, styleClass=text-input text-field], Text: 192.168.1.79,
astream_Terminated
astream_Terminated
astream_Terminated
Error occurred on line: 116 (asyncstreamsobject).
java.lang.NegativeArraySizeException
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readHelper(RandomAccessFile.java:348)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadObject(RandomAccessFile.java:335)
at b4j.example.asyncstreamsobject._astream_newstream(asyncstreamsobject.java:327)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:563)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:224)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:744)
--

I'm not sure this application will solve the problem, really. It seems to only send data from PC to the android device, not the way around I need it?

What I want to do is send an image taken from the camera and send it to me C# app on the PC. I can connect to the PC, send UDP packets, connect to the c# tcp server running, but Asyncstreams just does not seem to send data reliably. The only thing I have changed in the example is to use a different port of 6001. I have changed this in both apps.

I am using a Nexus4 updated to latest android version.

Do you have any more suggestions?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

androb

Member
Licensed User
Longtime User
I have just read the asyncstreams example page and I realise I did not read it properly the first time. I changed the code as noted to use big endian and this worked straight away.

Thank you for your assistance. I will be more careful in future.
 
Upvote 0
Top