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. Interface ASAPConnectionHandler. describes that fact:

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

Our ASAPPeerFS class implements this interface.

Our peers expect an input and output stream to run an ASAP session. Our ASAP application require means to create those streams.

Asking for those streams is not a harsh constraint. TCP provides streams, Bluetooth does, even LoRa-Wan can produce a stream based connection. In short, any protocol that provides streams can be used to run an ASAP session. That's a lot and far more than just Internet (IP based networks).

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