YANF4J publishes a 0.50-beta2 version, the most important improvement of this version is the introduction of the client Connection Non-blocking API, mainly the most recent work to use, so added. Two core classes Tcpconnectorcontroller and Udpconnectorcontroller are used for client connection control for TCP and UDP, respectively. For example, the current UDP echo client can be written as:
//client Echo Handler class Echoclienthandler extends Handleradapter {public void OnReceive (Session UdpS
Ession, Object t) {datagrampacket datagrampacket = (datagrampacket) t;
SYSTEM.OUT.PRINTLN ("recv:" + new String (Datagrampacket.getdata ())); @Override public void Onmessagesent (session session, Object T) {System.out.println ;quot;send:"
+ New String ((byte[)) t);
}//Connection code, and send UDP packet udpconnectorcontroller connector = new Udpconnectorcontroller ();
Connector.setsotimeout (1000);
Connector.sethandler (New Echoclienthandler ());
Connector.connect (New Inetsocketaddress (Inetaddress.getbyname (host), Port);
for (int i = 0; I < 10000 i++) {String s = "hello " + i;
Datagrampacket packet = new Datagrampacket (S.getbytes (), s.length ()); Connector.send (packet); }