You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/08/18 13:07:08 UTC

[plc4x] branch develop updated (1983930 -> e61badf)

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git.


    from 1983930  - Added a "rules" element to make the plugin happy on some maven versions.
     new a9669a0  Raw Socket works now reasonaly well, I think.
     new 91b4812  Cherry Picked some of the changes regarding Raw-Sockets: Raw Socket works now reasonaly well, I think.
     new e61badf  Cherry Picked some of the changes regarding Raw-Sockets: Raw Socket works now reasonaly well, I think.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 plc4j/utils/raw-sockets/pom.xml                    |   8 +
 .../plc4x/java/utils/rawsockets/RawIpSocket.java   |  26 ++-
 .../utils/rawsockets/netty/RawSocketChannel.java   |  44 ++++-
 .../utils/rawsockets/netty2/RawSocketChannel.java  | 202 +++++++++++++++++++++
 .../rawsockets/netty2/RawSocketChannelTest.java    |  96 ++++++++++
 5 files changed, 363 insertions(+), 13 deletions(-)
 create mode 100644 plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannel.java
 create mode 100644 plc4j/utils/raw-sockets/src/test/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannelTest.java


[plc4x] 03/03: Cherry Picked some of the changes regarding Raw-Sockets: Raw Socket works now reasonaly well, I think.

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit e61badf20509881e3ac29b40d5aef32995828718
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sun Aug 18 15:06:53 2019 +0200

    Cherry Picked some of the changes regarding Raw-Sockets: Raw Socket works now reasonaly well, I think.
---
 plc4j/utils/raw-sockets/pom.xml                                   | 8 ++++++++
 .../java/org/apache/plc4x/java/utils/rawsockets/RawIpSocket.java  | 1 -
 .../plc4x/java/utils/rawsockets/netty/RawSocketChannel.java       | 1 -
 .../plc4x/java/utils/rawsockets/netty2/RawSocketChannel.java      | 2 +-
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/plc4j/utils/raw-sockets/pom.xml b/plc4j/utils/raw-sockets/pom.xml
index 4ebeb00..5c9afd8 100644
--- a/plc4j/utils/raw-sockets/pom.xml
+++ b/plc4j/utils/raw-sockets/pom.xml
@@ -35,6 +35,14 @@
   <dependencies>
     <dependency>
       <groupId>io.netty</groupId>
+      <artifactId>netty-buffer</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.netty</groupId>
       <artifactId>netty-transport</artifactId>
     </dependency>
 
diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawIpSocket.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawIpSocket.java
index 804fa6a..d967f83 100644
--- a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawIpSocket.java
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawIpSocket.java
@@ -22,7 +22,6 @@ import org.pcap4j.packet.namednumber.*;
 import org.pcap4j.util.ByteArrays;
 import org.pcap4j.util.LinkLayerAddress;
 import org.pcap4j.util.MacAddress;
-import org.pcap4j.util.NifSelector;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java
index 680e8c6..2a73458 100644
--- a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java
@@ -21,7 +21,6 @@ package org.apache.plc4x.java.utils.rawsockets.netty;
 import io.netty.channel.*;
 import io.netty.channel.oio.OioByteStreamChannel;
 import org.apache.commons.lang3.NotImplementedException;
-import org.apache.plc4x.java.utils.rawsockets.RawIpSocket;
 import org.pcap4j.core.PcapHandle;
 import org.pcap4j.core.PcapNetworkInterface;
 import org.pcap4j.core.Pcaps;
diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannel.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannel.java
index 3e3c9a6..bc26ffc 100644
--- a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannel.java
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannel.java
@@ -26,13 +26,13 @@ import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelPromise;
 import io.netty.channel.oio.OioByteStreamChannel;
 import org.apache.commons.lang3.NotImplementedException;
+import org.apache.plc4x.java.utils.rawsockets.netty.RawSocketChannelConfig;
 import org.pcap4j.core.NotOpenException;
 import org.pcap4j.core.PacketListener;
 import org.pcap4j.core.PcapHandle;
 import org.pcap4j.core.PcapNativeException;
 import org.pcap4j.core.PcapNetworkInterface;
 import org.pcap4j.core.Pcaps;
-import org.pcap4j.packet.Packet;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 


[plc4x] 02/03: Cherry Picked some of the changes regarding Raw-Sockets: Raw Socket works now reasonaly well, I think.

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 91b481277ad27ea2286657f4c2d215a65f0dd454
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sun Aug 18 14:53:52 2019 +0200

    Cherry Picked some of the changes regarding Raw-Sockets: Raw Socket works now reasonaly well, I think.
---
 .../plc4x/java/utils/rawsockets/RawIpSocket.java   | 27 +++++++++----
 .../utils/rawsockets/netty/RawSocketChannel.java   | 45 +++++++++++++++++++---
 2 files changed, 59 insertions(+), 13 deletions(-)

diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawIpSocket.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawIpSocket.java
index 0215e3b..804fa6a 100644
--- a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawIpSocket.java
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/RawIpSocket.java
@@ -22,6 +22,7 @@ import org.pcap4j.packet.namednumber.*;
 import org.pcap4j.util.ByteArrays;
 import org.pcap4j.util.LinkLayerAddress;
 import org.pcap4j.util.MacAddress;
+import org.pcap4j.util.NifSelector;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,10 +32,7 @@ import java.io.InputStreamReader;
 import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.*;
 
 public class RawIpSocket {
@@ -42,7 +40,7 @@ public class RawIpSocket {
     private static final Logger logger = LoggerFactory.getLogger(RawIpSocket.class);
 
     private static final int SNAPLEN = 65536;
-    private static final int READ_TIMEOUT = 10;
+    private static final int READ_TIMEOUT = 10000;
 
     private static final String GATEWAY_ONLY_NETMASK = "255.255.255.255";
 
@@ -236,8 +234,11 @@ public class RawIpSocket {
                 pool.execute(() -> {
                     try {
                         receiveHandle.loop(-1, listener);
-                    } catch (PcapNativeException | InterruptedException | NotOpenException e) {
+                    } catch (PcapNativeException | NotOpenException e) {
                         logger.error("Error receiving ARP lookup", e);
+                    } catch (InterruptedException e) {
+                        logger.error("Interrupted! Error receiving ARP lookup", e);
+                        Thread.currentThread().interrupt();
                     }
                 });
 
@@ -296,6 +297,14 @@ public class RawIpSocket {
     private FirstHop getFirstHop(InetAddress remoteAddress) throws RawSocketException {
         byte[] remoteIp = remoteAddress.getAddress();
         // Iterate over all network interfaces.
+
+
+//        try {
+//            new NifSelector().selectNetworkInterface().getLinkLayerAddresses();
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+
         try {
             // First try if we can connect to the remote device directly.
             for (PcapNetworkInterface dev : Pcaps.findAllDevs()) {
@@ -322,8 +331,12 @@ public class RawIpSocket {
                         // If the current address would be able to connect to the remote
                         // address, return this device.
                         if (matches) {
+                            if (dev.getLinkLayerAddresses().isEmpty()) {
+                                continue;
+                            }
+                            LinkLayerAddress localMacAddress = dev.getLinkLayerAddresses().iterator().next();
                             return new FirstHop(dev, localAddress.getAddress(),
-                                dev.getLinkLayerAddresses().iterator().next(),
+                                localMacAddress,
                                 getMacAddress(dev, localAddress.getAddress(), remoteAddress));
                         }
                     }
diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java
index 1665686..680e8c6 100644
--- a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java
@@ -19,19 +19,34 @@ under the License.
 package org.apache.plc4x.java.utils.rawsockets.netty;
 
 import io.netty.channel.*;
+import io.netty.channel.oio.OioByteStreamChannel;
+import org.apache.commons.lang3.NotImplementedException;
+import org.apache.plc4x.java.utils.rawsockets.RawIpSocket;
+import org.pcap4j.core.PcapHandle;
+import org.pcap4j.core.PcapNetworkInterface;
+import org.pcap4j.core.Pcaps;
 
 import java.net.SocketAddress;
 
-public class RawSocketChannel extends AbstractChannel {
+public class RawSocketChannel extends OioByteStreamChannel {
 
     private static final ChannelMetadata METADATA = new ChannelMetadata(false, 16);
 
+    PcapHandle handle;
+
     protected class RawByteUnsafe extends AbstractChannel.AbstractUnsafe {
         @Override
         public void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
-            //getPipeline()
-            promise.setSuccess();
+            // Connect?!
+            try {
+                doConnect(remoteAddress, localAddress);
+                pipeline().fireChannelActive();
+                promise.setSuccess();
+            } catch (Exception e) {
+                promise.setFailure(e);
+            }
         }
+
     }
 
     public RawSocketChannel() {
@@ -49,6 +64,12 @@ public class RawSocketChannel extends AbstractChannel {
     }
 
     @Override
+    protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
+        PcapNetworkInterface nif = Pcaps.findAllDevs().get(0);
+        this.handle = nif.openLive(65536, PcapNetworkInterface.PromiscuousMode.PROMISCUOUS, 10);
+    }
+
+    @Override
     protected SocketAddress localAddress0() {
         return null;
     }
@@ -65,17 +86,19 @@ public class RawSocketChannel extends AbstractChannel {
 
     @Override
     protected void doDisconnect() throws Exception {
-        System.out.println("disconnect");
+        throw new NotImplementedException("");
     }
 
     @Override
     protected void doClose() throws Exception {
-        System.out.println("close");
+        if (this.handle != null) {
+            this.handle.close();
+        }
     }
 
     @Override
     protected void doBeginRead() throws Exception {
-        System.out.println("beginRead");
+        this.handle.getNextRawPacketEx();
     }
 
     @Override
@@ -103,4 +126,14 @@ public class RawSocketChannel extends AbstractChannel {
         return METADATA;
     }
 
+    @Override
+    protected boolean isInputShutdown() {
+        return false;
+    }
+
+    @Override
+    protected ChannelFuture shutdownInput() {
+        return null;
+    }
+
 }


[plc4x] 01/03: Raw Socket works now reasonaly well, I think.

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit a9669a0061f2dbdc70b71cef966838d0a1570ea7
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Sat Aug 17 18:18:47 2019 +0200

    Raw Socket works now reasonaly well, I think.
---
 .../utils/rawsockets/netty2/RawSocketChannel.java  | 202 +++++++++++++++++++++
 .../rawsockets/netty2/RawSocketChannelTest.java    |  96 ++++++++++
 2 files changed, 298 insertions(+)

diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannel.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannel.java
new file mode 100644
index 0000000..3e3c9a6
--- /dev/null
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannel.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.plc4x.java.utils.rawsockets.netty2;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelConfig;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelPromise;
+import io.netty.channel.oio.OioByteStreamChannel;
+import org.apache.commons.lang3.NotImplementedException;
+import org.pcap4j.core.NotOpenException;
+import org.pcap4j.core.PacketListener;
+import org.pcap4j.core.PcapHandle;
+import org.pcap4j.core.PcapNativeException;
+import org.pcap4j.core.PcapNetworkInterface;
+import org.pcap4j.core.Pcaps;
+import org.pcap4j.packet.Packet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.SocketTimeoutException;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * TODO write comment
+ *
+ * @author julian
+ * Created by julian on 2019-08-16
+ */
+public class RawSocketChannel extends OioByteStreamChannel {
+
+    private static final Logger logger = LoggerFactory.getLogger(RawSocketChannel.class);
+
+    private final RawSocketChannelConfig config;
+    private PcapNetworkInterface nif;
+    private PcapHandle handle;
+    public static ByteBuf buffer;
+    private Thread loopThread;
+
+    public RawSocketChannel() {
+        super(null);
+        config = new RawSocketChannelConfig(this);
+    }
+
+    @Override
+    protected boolean isInputShutdown() {
+        return false;
+    }
+
+    @Override
+    protected ChannelFuture shutdownInput() {
+        throw new NotImplementedException("");
+    }
+
+    @Override
+    protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
+        logger.debug("Connecting...");
+        nif = Pcaps.getDevByName("en0");
+        handle = nif.openLive(65535, PcapNetworkInterface.PromiscuousMode.PROMISCUOUS, 10);
+        buffer = Unpooled.buffer();
+        // Start loop in another Thread
+        loopThread = new Thread(() -> {
+            try {
+                handle.loop(-1, (PacketListener) packet -> {
+                    // logger.debug("Captured Packet from PCAP with length {} bytes", packet.getRawData().length);
+                    buffer.writeBytes(packet.getRawData());
+                });
+            } catch (PcapNativeException | NotOpenException e) {
+                // TODO this should close everything automatically
+                logger.error("Pcap4j loop thread died!", e);
+                pipeline().fireExceptionCaught(e);
+            } catch (InterruptedException e) {
+                logger.warn("PCAP Loop Thread was interrupted (hopefully intentionally)", e);
+                Thread.currentThread().interrupt();
+            }
+        });
+        loopThread.start();
+        activate(new PcapInputStream(buffer), new DiscardingOutputStream());
+    }
+
+    @Override
+    protected SocketAddress localAddress0() {
+        return new InetSocketAddress(1234);
+    }
+
+    @Override
+    protected SocketAddress remoteAddress0() {
+        return new InetSocketAddress(1234);
+    }
+
+    @Override
+    protected void doBind(SocketAddress localAddress) throws Exception {
+        throw new UnsupportedOperationException("");
+    }
+
+    @Override
+    protected void doDisconnect() throws Exception {
+        this.loopThread.interrupt();
+        if (this.handle != null) {
+            this.handle.close();
+        }
+    }
+
+    @Override protected int doReadBytes(ByteBuf buf) throws Exception {
+        if (handle == null || !handle.isOpen()) {
+            return -1;
+        }
+        try {
+            return super.doReadBytes(buf);
+        } catch (SocketTimeoutException ignored) {
+            return 0;
+        }
+    }
+
+    @Override
+    public ChannelConfig config() {
+        return this.config;
+    }
+
+    @Override
+    public boolean isOpen() {
+        return true;
+    }
+
+    @Override
+    protected AbstractUnsafe newUnsafe() {
+        return new RawSocketUnsafe();
+    }
+
+    private static class DiscardingOutputStream extends OutputStream {
+        @Override
+        public void write(int b) throws IOException {
+            // discard
+            logger.debug("Discarding {}", b);
+        }
+    }
+
+    private static class PcapInputStream extends InputStream {
+
+        final ByteBuf buf;
+
+        private PcapInputStream(ByteBuf buf) {
+            this.buf = buf;
+        }
+
+        @Override
+        public int available() throws IOException {
+            return buf.readableBytes();
+        }
+
+        @Override
+        public int read() throws IOException {
+            // Timeout 10 ms
+            final long timeout = System.nanoTime() + 10_000;
+            while (System.nanoTime() < timeout) {
+                if (buf.readableBytes() > 0) {
+                    return buf.readByte();
+                }
+            }
+            throw new SocketTimeoutException();
+        }
+
+    }
+
+    public class RawSocketUnsafe extends AbstractUnsafe {
+
+        @Override
+        public void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
+            try {
+                doConnect(remoteAddress, localAddress);
+                pipeline().fireChannelActive();
+                promise.setSuccess();
+            } catch (Exception e) {
+                promise.setFailure(e);
+            }
+        }
+
+    }
+}
diff --git a/plc4j/utils/raw-sockets/src/test/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannelTest.java b/plc4j/utils/raw-sockets/src/test/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannelTest.java
new file mode 100644
index 0000000..54029d0
--- /dev/null
+++ b/plc4j/utils/raw-sockets/src/test/java/org/apache/plc4x/java/utils/rawsockets/netty2/RawSocketChannelTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.plc4x.java.utils.rawsockets.netty2;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.*;
+import io.netty.channel.oio.OioEventLoopGroup;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GenericFutureListener;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TODO write comment
+ *
+ * @author julian
+ * Created by julian on 2019-08-16
+ */
+public class RawSocketChannelTest {
+
+    private static final Logger logger = LoggerFactory.getLogger(RawSocketChannelTest.class);
+
+    @Test
+    public void doConnect() throws InterruptedException {
+        Channel channel = null;
+        final EventLoopGroup workerGroup = new OioEventLoopGroup();
+        try {
+            Bootstrap bootstrap = new Bootstrap();
+            bootstrap.group(workerGroup);
+            bootstrap.channel(RawSocketChannel.class);
+            bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
+            bootstrap.option(ChannelOption.TCP_NODELAY, true);
+            // TODO we should use an explicit (configurable?) timeout here
+            // bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000);
+            bootstrap.handler(new ChannelInitializer<RawSocketChannel>() {
+                @Override
+                protected void initChannel(RawSocketChannel ch) throws Exception {
+                    System.out.println("Initialize Buffer!");
+                    ch.pipeline().addLast(new ChannelInboundHandlerAdapter(){
+                        @Override
+                        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+                            System.out.println(ByteBufUtil.prettyHexDump(((ByteBuf) msg)));
+                        }
+                    });
+                    ch.pipeline().addLast(new ChannelHandlerAdapter() {
+                        @Override
+                        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+                            cause.printStackTrace();
+                        }
+                    });
+                }
+            });
+            // Start the client.
+            final ChannelFuture f = bootstrap.connect("127.0.0.1", 1234);
+            // Wait for sync
+            f.sync();
+            // Wait till the session is finished initializing.
+            channel = f.channel();
+
+            System.out.println("Channel is connected and ready to use...");
+
+
+            channel.writeAndFlush(Unpooled.wrappedBuffer("Hallo".getBytes()));
+
+            // Prepare something to read
+            Thread.sleep(10_000);
+
+        } finally {
+            if (channel != null) {
+                channel.close().sync();
+            }
+            workerGroup.shutdownGracefully().sync();
+        }
+    }
+}
\ No newline at end of file