External app running a TCP server
The external application runs a TCP server on a specified port and acts as normal application server: when the bluetooth client requests a connection with a special IP, the BlueDUN service redirects the data packets to the local port on localhost (127.0.0.1).
Application settings - “Extensions” category:
Client application = unchecked
Redirect IP = the special IP associated to the external application [ default: 192.168.200.200 ]
Local port = the port number on localhost related to the TCP server running inside the external app [ default: 8001 ]
Actions to be performed in the external application:
1. Start the BlueDUN service [if not automatically started on device boot]:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.bluedunx","com.bluedunx.BlueDUNService"));
context.startService(intent);
2. Start up the TCP server for a given local port number
External app connecting as a TCP client
The external application connects to a TCP server running inside BlueDUN; the BlueDUN module redirects the data packets to the TCP socket created with the external device over the bluetooth channel, matching the port numbers.
The TCP server starts as soon as you start up the BlueDUN service on localhost (127.0.0.1) and opens the specified port.
Application settings - “Extensions” category:
Client application = checked
Redirect IP = the special IP associated to the external application [ default: 192.168.200.200 ]
Local port = the port number on localhost related to the TCP server running inside BlueDUN [default: 8001] and equivalent to the port number on the external device
Actions to be performed in the external application:
1. Start the BlueDUN service [if not automatically started on device boot]:
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.bluedunx","com.bluedunx.BlueDUNService"));
context.startService(intent);
2. Connect to the TCP server for the given port number
Note: this configuration needs the external app to be reconnected if the external device closes a connection created before.
For testing the service in both cases, you can download the source code of TCPClientServer
[ Android external app example implementing a TCP client / server ]
You don't need to perform the modem [AT commands] negotiation with your external device because BlueDUN+ supports also connections that start directly with PPP (LCP+NCP) negotiation.
No comments:
Post a Comment