Skip to content

IntroConnections

Thomas Schwotzer edited this page Sep 11, 2023 · 12 revisions

Connections and peers

An ASAP peer is a protocol engine. Not more, not less. An ASAP peer is not able set up any connection. It can run a ASAP session on an existing connection. InterfaceASAPConnectionHandler. describes that fact:

package net.sharksystem.asap;
...
public interface ASAPConnectionHandler {
     ...
     ASAPConnection handleConnection(InputStream is, OutputStream os) throws IOException, ASAPException;
     ...
}

Application developers can use ASAP peers to send messages. Applications can subscribe to receive incoming messages. Messenge routing is as opaque to application developers as they want it to be.

ASAP is a routing protocol based stream based point-to-point connection. This can be

  • layer 2 protocols e.g. based on Bluetooth, Wifi, LoRaWan etc.
  • layer 4 protocols, namely TCP or protocols on top.

ASAP peers are not aware of specific protocols which makes ASAP based applications independent from the underlying infrastructure, the unique feature of the whole ASAP/Shark project.

This part of our documentation is not for application developers, though. It is for developers who actually deal with specific connections. Especially our ASAPAndroid project makes heavy use of tools and features described here.

ASAPConnectionHandler

Each peer has - in general two sides:

  • one to application developers who should not care about specific netwoork protocols and
  • developers focussing on network connections who should not care about specific applications.
// somewehere in your app, a peer is created from a real class
ASAPPeerFS peer = new ASAPPeerFS(owner, rootFolder, supportedFormats);

// app developers focus on ASAPPeer interface
ASAPPeer asapPeer = peer;

// network support use ASAPConnectionHandler
ASAPConnectionHandler connectionHandler = peer;

Starting point of any application development is ASAPPeer interface. Its usage s discussed somewhere else in this documentation.

In the beginning, adding a new network support to an ASAP based application is extremly simple. There is just a single interface with a single method (that comes in different variants): ASAPConnectionHandler.

package net.sharksystem.asap;
...
public interface ASAPConnectionHandler {
     ...
     ASAPConnection handleConnection(InputStream is, OutputStream os) throws IOException, ASAPException;
     ...
}

ASAP application developers implement code that send asks ASAP peer to send messages and that deals with received messages.

ASAP network developers set up connections and ask peer to run ASAP sessions over it. That's done by calling handleConnection.

ASAP requires a stream based protocol which is most abstract represented by an Input- and an Outputstream.

This core project offers only rudimentary tools to create connections.

It offers a set of tools to deal single, multiple connection based applications, though. It offers also tool to deal with multiple protocol environments which are standard when it comes to applications running on mobile phones and often even in IoT scenarios.

Let's start with simple single connection based applications.

Clone this wiki locally