B4J Tutorial AsyncStreamsObject - Send and receive objects over the network

Discussion in 'B4J Tutorials' started by Erel, Nov 18, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User

    For new projects it is recommended to use B4XSerializator instead of this solution.



    [​IMG]

    AsyncStreamsObject allows you to send and receive objects instead of bytes.
    You can read more about it here: http://www.basic4ppc.com/android/fo...d-and-receive-objects-instead-of-bytes.30543/

    This example connects to the same Android example and allows you to communicate with the device.
    The device app acts as the server as the desktop firewalls usually blocks incoming connections.

    You can download the Android example here: http://www.basic4ppc.com/android/fo...e-objects-instead-of-bytes.30543/#post-202288
    Make sure to update B4A RandomAccessFile library to v1.6: http://www.basic4ppc.com/android/fo...handle-streams-of-any-size.30494/#post-177051

    Once you have a valid connection it is very simple to send and receive custom types, drawings, collections and files.
     

    Attached Files:

    Last edited: Aug 10, 2016
  2. myriaddev

    myriaddev Active Member Licensed User

    WoW! I got both sides to work (Android and PC)!! How do I pass the
    "correct/original fileNames" to the otherside ? I currently get internal names of
    the files that increment for the temporary file names on each side.
    THANKS!!!
     
    Last edited: Nov 22, 2013
  3. Erel

    Erel Administrator Staff Member Licensed User

    The simplest way is to add the file name to the key (instead of "file").
     
  4. YIM bunchhat

    YIM bunchhat Active Member Licensed User

    It is so cool....:). Excuse me, Is there any way to send without wifi but via internet?, Ex: the same as Skype.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. YIM bunchhat

    YIM bunchhat Active Member Licensed User

    Hello Erel,
    After I read briefly, I think it is not what I want to do. I am interesting in communication from one device to other device wireless. I ever ask you about CCTV from phone to phone, now I can make it work properly. but I want to upgrade it use without wifi but via internet. I think is the same to Skype that can chat, can live video, send file..etc.....:D
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    It is not possible to directly connect two devices over the internet. Mobile provides do not allow incoming connections.

    Such services use online servers.
     
    Antonio1 likes this.
  8. YIM bunchhat

    YIM bunchhat Active Member Licensed User

    Ok thank I just want to know is it possible or not......:D
     
  9. myriaddev

    myriaddev Active Member Licensed User

    I am now getting IP: 192.168.2.1 after BAJ 1.0 and using ipconfig it tells me
    local ip is 192.168.0.97.
    On client's xp AsyncStreamsObject IP: 192.168.2.1 and its local ip 192.168.0.28.
    Before BAJ 1.0, I could connect.
    Please help.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    The problem is not in B4J 1.0. Something has changed in your network.
     
  11. myriaddev

    myriaddev Active Member Licensed User

    Hi Erel. I took your idea, and removed VMware and Virtualbox from my Windows 7 system
    and now AsyncStreamObject BAJ now correctly reports it's local IP! THANKS!!

    Currently I can connect from PC to Android(s), and from Android to Android but NOT from
    Android to PC (two physical locations)l?! Works great once connected. Any ideas ?
     
    allover likes this.
  12. Erel

    Erel Administrator Staff Member Licensed User

    Windows firewall blocks incoming connections. You will need to open the port in the firewall settings.
     
  13. slowtime

    slowtime Active Member Licensed User

    Hi,
    If I change in AsyncStreamsObject TempFolder="C:\" (or other Path ) I can't receive file.

    Code:
    Public Sub Initialize (TargetModule As Object, EventName As String)
        target = TargetModule
        
    Event = EventName
        
    'TempFolder = File.DirTemp
        TempFolder="c:\"
        
    Log(File.DirTemp)
    End Sub
    Can you help me ?

    Thank you
    Ciao
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    I guess that c:\ is a restricted folder. Try to use a folder such as c:\temp.
     
    micro likes this.
  15. slowtime

    slowtime Active Member Licensed User

    Thank you, but c:\temp is not the solution. It is strange; file.dirTemp resuts inside a path locked in Windo seven but it is running. I also tryied in a usbPen Drive and a external HD but it is not run.
    Ciao and good year.
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    C:\temp was just an example. The problem is that the root folder is restricted under Windows. If you like you can run your app as an administrator.
     
    Jimmi Permana likes this.
  17. slowtime

    slowtime Active Member Licensed User

    Thank you, I'll try
    Ciao
     
  18. pauleffect

    pauleffect Member Licensed User

    could it be ported to visual studio? i know it's a long shot but....

    I'm trying to append some macro for automation purposes and i'd be great if i could cut the middleman, so to speak.
     
  19. Erel

    Erel Administrator Staff Member Licensed User

  20. Asim A Baki

    Asim A Baki Active Member Licensed User

    Please provide a link to this Desktop example in the article
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice