tranquil/org.quietmodem.Restful

Partager

news describe

Restful Modem Chat

org.quietmodem.Restful helps you to pass data through the speakers on your Android instrument. This library can characteristic both as a raw body layer or as a UDP/TCP stack.

This bundle contains prebuilt library files for libquiet and tranquil-lwip moreover as their dependencies. On high of that, it adds Java bindings which closely mimic the familiar interfaces from the java.get.* bundle.

This bundle is provided under the three-clause BSD license. The licenses of its dependencies are also integrated and are licensed under a combine of BSD and MIT.

Restful comes with enhance for armeabi-v7a, arm64-v8a, x86, and x86_64. It requires Android API 14 for 32-bit mode and API 21 for 64-bit mode. It requires ideal the RECORD_AUDIO permission.

For making an are trying out purposes, Genymotion is highly if truth be told useful over the default emulator. Genymotion offers internet entry to to the microphone whereas the default Android Studio one would no longer and must throw an exception when Restful attempts to employ the microphone.

Why sound? Is never any longer if truth be told that old-customary?

Whereas possibilities are you’ll perhaps perhaps even be primitive ample, possibilities are you’ll perhaps perhaps also attach in thoughts the employ of dial-up modems to glue to the cyber web. In a sense, this bundle brings that help. Whereas or no longer it’s correct that here is considerably of a retro methodology, appreciate in thoughts the advantages of the employ of sound.

  • Highly corrupt-platform. Any instrument with speakers and a microphone and ample computational energy can employ this medium to focus on.

  • No pairing. Not like Bluetooth, sound could perhaps perhaps be utilized straight without the must pair devices. This reduces the friction and improves the user trip.

  • Embeddable verbalize material. Much like a QR code, short packets of files could perhaps perhaps be encoded into streaming or recorded audio and could perhaps perhaps then be later decoded by this bundle.

What does it sound like?

The answer to this depends upon which working mode you to decide. Restful offers audible and near-ultrasonic modes. Audible modes sound one thing like a puff of air. The near-ultrasonic modes urge at 17+kHz and are only about inaudible to adults. Both mode can characteristic at pretty low volumes as long as there could be no longer any longer too unprecedented background noise.

How like a flash does it lag?

Restful’s offered audible mode transfers at roughly 7kbps. In conditions the build two devices are connected over a cable (by job of three.5mm jack) it could perhaps in point of fact urge in cable mode, which transfers at roughly 64kbps.

Other Platforms

Desktop/Computer pc: libquiet and tranquil-lwip

Javascript: tranquil-js (UDP/TCP coming soon)

iOS: QuietModemKit

Apps that employ org.quietmodem.Restful

Restful Part – A proof of theory app that enables textual verbalize material and links to be shared from one instrument to one other.

Restful could perhaps perhaps be utilized both as a raw body layer or in UDP/TCP mode. For the latter, it offers the lwIP TCP stack which operates completely independently from the stack offered by Android.

Create obvious that that to appreciate the Android NDK installed and space the set of it at ndk.dir in native.properties. That is known to form the JNI wrapper integrated on this project.

Frame Mode

Assuming we’re working from MainActivity.java, we open with

import java.io.IOException;
import org.quietmodem.Restful.*;

FrameReceiverConfig receiverConfig = null;
FrameTransmitterConfig transmitterConfig = null;

are trying {
    transmitterConfig = contemporary FrameTransmitterConfig(
            this,
            "audible-7k-channel-0");
    receiverConfig = contemporary FrameReceiverConfig(
            this,
            "audible-7k-channel-0");
} bewitch (IOException e) {
    // could perhaps no longer form configs
}

FrameReceiver receiver = null;
FrameTransmitter transmitter = null;

are trying {
    receiver = contemporary FrameReceiver(receiverConfig);
    transmitter = contemporary FrameTransmitter(transmitterConfig);
} bewitch (ModemException e) {
    // could perhaps no longer space up receiver/transmitter
}

This sets up our transmitter and receiver the employ of the packaged configuration. We take hold of the audible mode here. Now we can transmit.

On one facet shall we urge

// space receiver to block till a body is obtained
// by default receivers are nonblocking
receiver.setBlocking(0, 0);

byte[] buf = contemporary byte[1024];
long recvLen = 0;
are trying {
    recvLen = receiver.internet(buf);
} bewitch (IOException e) {
    // be taught timed out
}

And on the diverse facet

String payload = "Hiya, World!";
are trying {
    transmitter.ship(payload.getBytes());
} bewitch (IOException e) {
    // our message could perhaps very well be too long or the transmit queue beefy
}

That’s ample to ship our body across. Frame mode is purposeful after we must ship little bits of files that can without problems slot in one body and form no longer want a theory of a sender or receiver, that is, frames are a broadcast medium.

UDP/TCP Mode

If we must form interactions between two devices, or if we need retransmits and computerized data segmentation, then TCP is the device to head.

First we form a contemporary NetworkInterface.

import java.io.IOException;
import java.get.SocketException;
import org.quietmodem.Restful.*;

FrameReceiverConfig receiverConfig = null;
FrameTransmitterConfig transmitterConfig = null;

are trying {
    transmitterConfig = contemporary FrameTransmitterConfig(
            this,
            "audible-7k-channel-0");
    receiverConfig = contemporary FrameReceiverConfig(
            this,
            "audible-7k-channel-0");
} bewitch (IOException e) {
    // could perhaps no longer form configs
}

NetworkInterfaceConfig conf = contemporary NetworkInterfaceConfig(
            receiverConfig,
            transmitterConfig);

NetworkInterface intf = null;
are trying {
    intf = contemporary NetworkInterface(conf);
} bewitch (ModemException e) {
    // network interface failure
}

This instance omits an IP take care of and netmask from NetworkInterfaceConfig() which tells Restful to invent an Auto IP. This can also robotically set our interface an take care of, even supposing it does bewitch several seconds to probe and resolve an take care of after we instantiate the interface.

If we’re the employ of Restful in an ad-hoc manner, we’ll must in discovering any peers nearby. We are going to have the skill to form this by the employ of a broadcast UDP packet.

On every facet shall we urge one thing like this.

// org.quietmodem.Restful.DatagramSocket
DatagramSocket s = null;
are trying {
    // bind to wildcard:3333 -- label that here is
    // the employ of org.quietmodem.Restful.InetSocketAddress
    // no longer java.get.InetSocketAddress
    sSend = contemporary DatagramSocket(contemporary InetSocketAddress("0.0.0.0", 3333));
    // listen on 3334
    sRecv = contemporary DatagramSocket(contemporary InetSocketAddress("0.0.0.0", 3334));

    // don't block for higher than 10 seconds
    sRecv.setSoTimeout(10000);

    // internet broadcast permission
    sSend.setBroadcast(correct);
} bewitch (SocketException e) {
    // exception creating DatagramSocket
}

byte[] ship = "MARCO".getBytes();
byte[] recv = contemporary byte[1024];
InetSocketAddress search for = null;
whereas (correct) {
    // prepare to form a broadcast to port 3334
    // as soon as more, here is org.quietmodem.Restful.DatagramPacket
    DatagramPacket p = contemporary DatagramPacket(ship, ship.length,
                    contemporary InetSocketAddress("169.254.255.255", 3334));
    are trying {
        sSend.ship(p);
    } bewitch (IOException e) {
        // exception sending on DatagramSocket
    }

    DatagramPacket pRecv = contemporary DatagramPacket(recv, recv.length);
    boolean obtained = false;
    are trying {
        sRecv.internet(pRecv);

        obtained = correct;
        search for = pRecv.getSocketAddress();

        // answer so as that the diverse search for knows we're here
        p.setData("POLO".getBytes());
        p.setSocketAddress(search for);
        sSend.ship(p);
    } bewitch (IOException e) {
        // exception receiving on DatagramSocket
    }

    if (obtained) {
        spoil;
    }

    // our 10-2d be taught timeout acts as a snooze
    // continue broadcasting till we internet a chunk
}

// now employ the hunt for's take care of by hook or by crook....
// continue sending UDP or set up a TCP connection
// on one other port

// when finished, end sSend, sRecv and intf

Be taught More

(Visité 16 fois, 1 aujourd'hui)

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *