package grizzlyproto; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.TransportFactory; import org.glassfish.grizzly.filterchain.FilterAdapter; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.memory.ByteBufferManager; import org.glassfish.grizzly.nio.transport.UDPNIOTransport; public class TReceiver { public static void main(String[] args) { TReceiver receiver = new TReceiver(); receiver.run(); } public void run() { UDPNIOTransport transport = TransportFactory.getInstance().createUDPTransport(); transport.getFilterChain().add(new TransportFilter()); transport.getFilterChain().add(new FilterAdapter() { @Override public NextAction handleRead(FilterChainContext ctx, NextAction nextAction) throws IOException { System.out.println("got read"); return super.handleRead(ctx, nextAction); } }); try { transport.start(); } catch (IOException e1) { e1.printStackTrace(); } InetSocketAddress firstReceiver = new InetSocketAddress("localhost", 11000); InetSocketAddress firstSender = new InetSocketAddress("localhost", 12000); Future futureConnection = null; try { futureConnection = transport.connect(firstSender, firstReceiver); } catch (IOException e) { e.printStackTrace(); } try { Connection connection = futureConnection.get(); ByteBufferManager manager = new ByteBufferManager(); Buffer buffer = manager.allocate(100); buffer.limit(100); // write succeeds (seen in wireshark) transport.write(connection, firstSender, buffer, null); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }