Getting Started

This guide walks you through your first jNetWorks application: capturing packets, applying filters, and processing them in parallel across multiple CPU cores.

jNetWorks makes high-performance capture simple with a fluent, type-safe API — the same code works for development (libpcap) or production (DPDK/Napatech).

1. Add the Dependency

<dependency>
    <groupId>com.slytechs.sdk</groupId>
    <artifactId>jnetworks-sdk</artifactId>
    <version>3.0.0</version>
</dependency>

The core API and protocol dissection are fully Apache 2.0 licensed. DPDK and Napatech backends require a commercial license.

2. Activate License (Commercial Features Only)

If using DPDK or Napatech backends:

Net.activateLicense("your-commercial-key"); // Optional for libpcap

3. Basic Single-Stream Capture

Start with the simplest possible live capture:

import com.slytechs.sdk.jnetworks.Net;
import com.slytechs.sdk.jnetworks.PacketStream;
import com.slytechs.sdk.jnetworks.pcap.PcapBackend;
import com.slytechs.sdk.protocol.core.Packet;

try (Net net = new PcapBackend()) {

    PacketStream stream = net.createPacketStream("main");

    net.capture("en0")           // Capture from interface en0
       .filter("tcp port 80")    // Optional BPF filter
       .pipe(stream)             // Send packets to our stream
       .apply();

    while (stream.isActive()) {
        Packet packet = stream.take();
        System.out.printf("Captured %d bytes (wirelen=%d)%n",
                packet.capLength(), packet.wireLength());

        stream.release(packet);  // Always release when done
    }

} catch (Exception e) {
    e.printStackTrace();
}

Scale effortlessly across CPU cores:

5. Typed Protocol Streams (Zero Manual Parsing)

Receive fully dissected objects directly:

Next Steps

  • Tutorials – Full working examples (multi-core, typed streams)

  • Public API – Deep dive into builders and configuration

  • Hardware Integration – Switching to DPDK or Napatech

Welcome to wire-speed network programming in Java.

Last updated