package com.github.r1j0.statsd.client;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoConnector;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioDatagramConnector;


public class StatsdClient {

	private static final String HOST = "127.0.0.1";
	private static final int PORT = 39390;


	public static void main(String[] args) throws IOException, InterruptedException {
		IoConnector connector = new NioDatagramConnector();
		connector.getSessionConfig().setReadBufferSize(2048);

		connector.getFilterChain().addLast("logger", new LoggingFilter());
		connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));

		connector.setHandler(new StatsdClientHandler("Hello Server.. äöüß"));
		ConnectFuture future = connector.connect(new InetSocketAddress(HOST, PORT));
		future.awaitUninterruptibly();

		if (!future.isConnected()) {
			return;
		}

		IoSession session = future.getSession();
		session.getConfig().setUseReadOperation(true);
		session.getCloseFuture().awaitUninterruptibly();

		System.out.println("After Writing");
		connector.dispose();
	}
}

@@ -520,17 +520,16 @@
 ector;%0A%0A
-%0A
 public c
@@ -723,16 +723,217 @@
 ption %7B%0A
+%09%09for (int i = 0; i %3C 100; i++) %7B%0A%09%09%09new Automatic().run();%0A%09%09%7D%0A%0A%09%09System.exit(0);%0A%09%7D%0A%0A%0A%09public static class Automatic extends Thread %7B%0A%0A%09%09public Automatic() %7B%0A%09%09%09super();%0A%09%09%7D%0A%0A%0A%09%09public void run() %7B%0A%09
 %09%09IoConn
@@ -976,24 +976,25 @@
 nector();%0A%09%09
+%09
 connector.ge
@@ -1032,24 +1032,25 @@
 ize(2048);%0A%0A
+%09
 %09%09connector.
@@ -1106,16 +1106,17 @@
 ter());%0A
+%09
 %09%09connec
@@ -1234,16 +1234,17 @@
 )));%0A%0A%09%09
+%09
 connecto
@@ -1281,16 +1281,17 @@
 andler(%22
+ 
 Hello Se
@@ -1308,16 +1308,17 @@
 %C3%9F%22));%0A%09%09
+%09
 ConnectF
@@ -1390,42 +1390,10 @@
 ));%0A
-%09%09future.awaitUninterruptibly();%0A
 %0A
+%09
 %09%09if
@@ -1422,16 +1422,17 @@
 )) %7B%0A%09%09%09
+%09
 return;%0A
@@ -1433,19 +1433,21 @@
 turn;%0A%09%09
+%09
 %7D%0A%0A
+%09
 %09%09IoSess
@@ -1479,24 +1479,25 @@
 ession();%0A%09%09
+%09
 session.getC
@@ -1531,16 +1531,17 @@
 (true);%0A
+%09
 %09%09sessio
@@ -1546,89 +1546,22 @@
 ion.
-getCloseFuture().awaitUninterruptibly();%0A%0A%09%09System.out.println(%22After Writing%22
+close(true
 );%0A
+%09
 %09%09co
@@ -1579,13 +1579,17 @@
 pose();%0A
+%09%09%7D%0A
 %09%7D%0A%7D%0A

use simple threads