B4AServer is now deprecated. There are simpler and more powerful solutions available with B4J.
Overview
B4AServer is now available. The purpose of B4AServer is to simplify development of in-house applications.
B4AServer makes it simple to reliably communicate one or more Android devices with a desktop computer acting as the server over the local network. The desktop computer is a regular computer running the desktop component of B4AServer.
Currently the server supports three "actions":
- Download files (desktop to device).
- Upload files (device to desktop).
- Run predefined executables or shell commands and return the result to the device.
Using these three actions you can easily integrate your Android application with an existing system. For example you can write a desktop program (using your preferred programming language) that exports data from your database based on the arguments it receives and stores the data in a file. The device will send a shell request that will run the program and when it completes successfully it will download the file.
The desktop server can also serve as a complementary service for tasks that are much easier to handle on a desktop. For example the device can upload a file and then send a shell request that will print this file.
While this post is pretty long, the actual configuration is rather simple. I recommend you to give it a try. B4AServer can solve many tasks easily and reliably.
Components and usage
B4AServer is made of three components.
Desktop server, device client service and code modules and "board" web service (php script).
To overcome firewall issues with incoming connections, the desktop server connects to the device. When a device wants to connect to the desktop server it calls the board web service and sends the board web service its own IP address. The desktop server checks the web service for waiting devices every couple of seconds. When a waiting device is discovered the server tries to connect to this device. Once there is a connection the communication is done directly between the device and the desktop server.
All the client communication issues are implemented inside the service and code modules. The public interface is very simple.
Device code and configuration:
The device program needs two parameters. The URL of the board web service and the name of the desktop server. The name of the desktop server can be any string that you want. It is used by the board service to differentiate between different desktop servers using the same board service.
In this code we set the URL, server name and the Activity that will handle the TaskComplete event:
Note that the live "board" link included in the examples code should only be used for development. There are no guarantees whatsoever regarding its availability.
Working with B4AServer is done by sending tasks. There are three relevant methods in B4AServer module: SendFile, ReceiveFile and Shell. Each of these subs return an Int value which serves as the task id.
Later when the task is completed (whether successful or not) the TaskComplete sub will be called. The task id will be passed to this method as part of the TaskResult parameter.
For example to download an image named logo.jpg from the desktop server and set it as the Activity background we can use this code:
The other two subs are:
B4AServer.SendFile (Dir As String, FileName As String) As Int
Which uploads a file to the server.
B4AServer.Shell (ShellCommand As String, Args As List) As Int
Which makes the server run the predefined command with the given arguments. Pass Null if no arguments are required.
Configuring the desktop server
The desktop server configuration is stored in a file named config.properties.
You must edit this file and set the ServerName property to match the chosen server name.
You can set any number of shell commands. The format is Shell.<shellcommand>.
Not that you should escape forward slashes with another forward slash as shown above in Shell.Print.
The desktop server is a java program so it can run on any operating system with Java installed. A batch file is included named run.bat that will start the server. After changing a configuration parameter you will need to restart the server by closing its window and running it again.
Configuring the board web service (can be skipped during development)
During development you can use the web service link that is included in the examples.
The board web service is a php script that communicates with a MySQL database.
You will need to create a database and a user account that can access the database.
Then edit b4a_server.php and set the four fields at the top of the file:
The script will create the tables on the first run.
A shared hosting that supports MySQL and PHP should suffice for running the board web service.
Please feel free to suggest any suggestion or possible use cases.
The files are available here. See the second post there for information about using the emulator with B4AServer.
Examples:
Printing with B4AServer: http://www.b4x.com/forum/basic4andr...inting-android-using-b4aserver.html#post53634
Managing deployment and updates of multiple applications on multiple devices: http://www.b4x.com/forum/basic4andr...ons-multiple-devices-b4aserver.html#post53738
Accessing any database or system with B4AServer: http://www.b4x.com/forum/basic4andr...-any-database-system-b4aserver.html#post53786
Overview
B4AServer is now available. The purpose of B4AServer is to simplify development of in-house applications.
B4AServer makes it simple to reliably communicate one or more Android devices with a desktop computer acting as the server over the local network. The desktop computer is a regular computer running the desktop component of B4AServer.
Currently the server supports three "actions":
- Download files (desktop to device).
- Upload files (device to desktop).
- Run predefined executables or shell commands and return the result to the device.
Using these three actions you can easily integrate your Android application with an existing system. For example you can write a desktop program (using your preferred programming language) that exports data from your database based on the arguments it receives and stores the data in a file. The device will send a shell request that will run the program and when it completes successfully it will download the file.
The desktop server can also serve as a complementary service for tasks that are much easier to handle on a desktop. For example the device can upload a file and then send a shell request that will print this file.
While this post is pretty long, the actual configuration is rather simple. I recommend you to give it a try. B4AServer can solve many tasks easily and reliably.
Components and usage
B4AServer is made of three components.
Desktop server, device client service and code modules and "board" web service (php script).
To overcome firewall issues with incoming connections, the desktop server connects to the device. When a device wants to connect to the desktop server it calls the board web service and sends the board web service its own IP address. The desktop server checks the web service for waiting devices every couple of seconds. When a waiting device is discovered the server tries to connect to this device. Once there is a connection the communication is done directly between the device and the desktop server.
All the client communication issues are implemented inside the service and code modules. The public interface is very simple.
Device code and configuration:
The device program needs two parameters. The URL of the board web service and the name of the desktop server. The name of the desktop server can be any string that you want. It is used by the board service to differentiate between different desktop servers using the same board service.
In this code we set the URL, server name and the Activity that will handle the TaskComplete event:
B4X:
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
B4AServer.Initialize("http://xx.xx.xx.xx/b4a_server.php", ServerName, "Main")
End If
Working with B4AServer is done by sending tasks. There are three relevant methods in B4AServer module: SendFile, ReceiveFile and Shell. Each of these subs return an Int value which serves as the task id.
Later when the task is completed (whether successful or not) the TaskComplete sub will be called. The task id will be passed to this method as part of the TaskResult parameter.
For example to download an image named logo.jpg from the desktop server and set it as the Activity background we can use this code:
B4X:
Sub btnReceiveFile_Click
'imgTask is a global variable
imgTask = B4AServer.ReceiveFile("logo.jpg") 'Sends a download file request
End Sub
Sub TaskComplete(Result As TaskResult)
If Result.Id = imgTask AND Result.Success = True Then
Activity.SetBackgroundImage(LoadBitmap(B4AServer.DownloadFilesFolder, Result.Id))
End If
End Sub
B4AServer.SendFile (Dir As String, FileName As String) As Int
Which uploads a file to the server.
B4AServer.Shell (ShellCommand As String, Args As List) As Int
Which makes the server run the predefined command with the given arguments. Pass Null if no arguments are required.
Configuring the desktop server
The desktop server configuration is stored in a file named config.properties.
You must edit this file and set the ServerName property to match the chosen server name.
B4X:
#This is the unique server name you choose.
ServerName=test1
#Folder for files that can be downloaded to a device
InputFolder=files
#folder for uploaded files
OutputFolder=files
#number of devices that can connect at the same time
WorkerThreads=5
#link to the board server
BoardUrl=http://xx.xx.xx.xx/b4a_server.php
#Interval measured in seconds. The desktop server polls the board server every x seconds.
CheckInterval=5
#list of shell commands
Shell.Print="c:\\program files\\PrintHTML\\printhtml.exe" printername="novapdf" header="" footer=""
Shell.Dir=cmd.exe /c dir files
Not that you should escape forward slashes with another forward slash as shown above in Shell.Print.
The desktop server is a java program so it can run on any operating system with Java installed. A batch file is included named run.bat that will start the server. After changing a configuration parameter you will need to restart the server by closing its window and running it again.
Configuring the board web service (can be skipped during development)
During development you can use the web service link that is included in the examples.
The board web service is a php script that communicates with a MySQL database.
You will need to create a database and a user account that can access the database.
Then edit b4a_server.php and set the four fields at the top of the file:
B4X:
$databasehost = "localhost";
$databasename = "xxxx";
$databaseusername ="xxxx";
$databasepassword = "xxxx";
A shared hosting that supports MySQL and PHP should suffice for running the board web service.
Please feel free to suggest any suggestion or possible use cases.
The files are available here. See the second post there for information about using the emulator with B4AServer.
Examples:
Printing with B4AServer: http://www.b4x.com/forum/basic4andr...inting-android-using-b4aserver.html#post53634
Managing deployment and updates of multiple applications on multiple devices: http://www.b4x.com/forum/basic4andr...ons-multiple-devices-b4aserver.html#post53738
Accessing any database or system with B4AServer: http://www.b4x.com/forum/basic4andr...-any-database-system-b4aserver.html#post53786
Last edited: