Android Tutorial [B4X] Network + AsyncStreams + B4XSerializator

Status
Not open for further replies.
Better implementation, based on B4XPages: https://www.b4x.com/android/forum/t...-asyncstreams-b4xserializator.119011/#content

New video tutorial:





SS-2016-10-19_15.32.02.jpg



SS-2017-07-11_10.53.45.png


SS-2017-07-11_11.03.32.png



This is a simple and important example. It demonstrates several good practices related to network communication.

1. The network related code is in the Starter service. The network state is also stored in the starter service.
2. The Activity is only responsible for the UI.
3. Using B4XSerializator it is simple to work with types instead of strings or bytes. In this case the message structure is:
B4X:
Type MyMessage (Name As String, Age As Int, Image() As Byte)
- Bitmaps cannot be directly serialized so we need to convert the bitmap to bytes and vice versa.
- B4XSerializator is cross platform compatible. This means that you can send the exact same structure to B4J or B4i applications.

Platform specific notes

- The code in B4J and B4i is a bit simpler as there is no need to use a second module (starter module). All modules are always active in B4J and B4i.
- In B4i we need to recreate the server socket when the application becomes active as the socket can become stale while the app is in the background (and not killed).
- Windows firewall blocks incoming connections so if you want to connect to the B4J app, you need to first allow incoming communication on the relevant port.
 

Attachments

  • B4i_Network.zip
    4.8 KB · Views: 1,624
  • B4J_Network.zip
    4.4 KB · Views: 2,710
  • B4A_NetworkOld.zip
    9.2 KB · Views: 2,104
  • B4A_Network.zip
    9.2 KB · Views: 4,821
Last edited:

hears

Active Member
Licensed User
i try use this NETWORK libary connect to ROUTER by SSH ,I have looked by log ,it is connect succus , buy i can not send command by
CallSub2(Starter, "SendData", data2.GetBytes)

in telnet mode ,this work good. when i change to 22 PORT , this not work now .can you help me ?
 
Status
Not open for further replies.
Top