@@ -477,9 +477,54 @@ public void run() {
477477 }
478478 }
479479
480- public AsyncSocket connectDatagram (final SocketAddress remote ) throws IOException {
480+ public AsyncDatagramSocket connectDatagram (final String host , final int port ) throws IOException {
481481 final DatagramChannel socket = DatagramChannel .open ();
482- final AsyncNetworkSocket handler = new AsyncNetworkSocket ();
482+ final AsyncDatagramSocket handler = new AsyncDatagramSocket ();
483+ handler .attach (socket );
484+ // ugh.. this should really be post to make it nonblocking...
485+ // but i want datagrams to be immediately writable.
486+ // they're not really used anyways.
487+ run (new Runnable () {
488+ @ Override
489+ public void run () {
490+ try {
491+ final SocketAddress remote = new InetSocketAddress (host , port );
492+ handleSocket (handler );
493+ socket .connect (remote );
494+ }
495+ catch (Exception e ) {
496+ e .printStackTrace ();
497+ }
498+ }
499+ });
500+ return handler ;
501+ }
502+
503+ public AsyncDatagramSocket openDatagram () throws IOException {
504+ final DatagramChannel socket = DatagramChannel .open ();
505+ final AsyncDatagramSocket handler = new AsyncDatagramSocket ();
506+ handler .attach (socket );
507+ // ugh.. this should really be post to make it nonblocking...
508+ // but i want datagrams to be immediately writable.
509+ // they're not really used anyways.
510+ run (new Runnable () {
511+ @ Override
512+ public void run () {
513+ try {
514+ socket .socket ().bind (null );
515+ handleSocket (handler );
516+ }
517+ catch (Exception e ) {
518+ e .printStackTrace ();
519+ }
520+ }
521+ });
522+ return handler ;
523+ }
524+
525+ public AsyncDatagramSocket connectDatagram (final SocketAddress remote ) throws IOException {
526+ final DatagramChannel socket = DatagramChannel .open ();
527+ final AsyncDatagramSocket handler = new AsyncDatagramSocket ();
483528 handler .attach (socket );
484529 // ugh.. this should really be post to make it nonblocking...
485530 // but i want datagrams to be immediately writable.
0 commit comments