Пример #1
0
            public static xConstructorArguments Of(int port)
            {
                // X:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPFloats\ChromeUDPFloats\Application.cs

                var xMulticastSocket = default(java.net.MulticastSocket);
                var xDatagramSocket  = default(java.net.DatagramSocket);

                // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs
                return(new xConstructorArguments
                {
                    port = port,

                    vMulticastSocket = delegate
                    {
                        if (xMulticastSocket != null)
                        {
                            return xMulticastSocket;
                        }


                        #region datagramSocket

                        try
                        {
                            xMulticastSocket = new java.net.MulticastSocket(port);
                            xDatagramSocket = xMulticastSocket;
                        }
                        catch
                        {
                            throw;
                        }
                        #endregion

                        return xMulticastSocket;
                    },

                    vDatagramSocket = delegate
                    {
                        if (xDatagramSocket != null)
                        {
                            return xDatagramSocket;
                        }

                        try
                        {
                            xDatagramSocket = new java.net.DatagramSocket(port);
                        }
                        catch
                        {
                            throw;
                        }

                        return xDatagramSocket;
                    }
                });
            }
Пример #2
0
            public static xConstructorArguments Of(IPEndPoint e)
            {
                var xMulticastSocket = default(java.net.MulticastSocket);
                var xDatagramSocket  = default(java.net.DatagramSocket);

                // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs
                return(new xConstructorArguments
                {
                    vMulticastSocket = delegate
                    {
                        if (xMulticastSocket != null)
                        {
                            return xMulticastSocket;
                        }


                        #region datagramSocket

                        try
                        {
                            xMulticastSocket = new java.net.MulticastSocket(e.Port);
                            xDatagramSocket = xMulticastSocket;
                        }
                        catch
                        {
                            throw;
                        }
                        #endregion

                        return xMulticastSocket;
                    },

                    vDatagramSocket = delegate
                    {
                        if (xDatagramSocket != null)
                        {
                            return xDatagramSocket;
                        }

                        try
                        {
                            xDatagramSocket = new java.net.DatagramSocket(e.Port);
                        }
                        catch
                        {
                            throw;
                        }

                        return xDatagramSocket;
                    }
                });
            }
Пример #3
0
        static java.net.DatagramSocket try_new_DatagramSocket(int port)
        {
            #region datagramSocket
            var datagramSocket = default(java.net.DatagramSocket);

            try
            {
                // http://developer.android.com/reference/java/net/DatagramSocket.html
                // Constructs a UDP datagram socket which is bound to the specific port aPort on the localhost. Valid values for aPort are between 0 and 65535 inclusive.
                datagramSocket = new java.net.DatagramSocket(port);
            }
            catch
            {
                throw;
            }
            #endregion

            return(datagramSocket);
        }
Пример #4
0
        // what comes after tcp?
        // what about async API ?

        // X:\jsc.svn\examples\java\hybrid\JVMCLRUDPReceiveAsync\JVMCLRUDPReceiveAsync\Program.cs
        // X:\jsc.svn\examples\java\hybrid\JVMCLRUDPSendAsync\JVMCLRUDPSendAsync\Program.cs
        // X:\jsc.svn\examples\java\ConsoleMulticastExperiment\ConsoleMulticastExperiment\Program.cs
        // X:\jsc.svn\examples\java\android\AndroidServiceUDPNotification\AndroidServiceUDPNotification\ApplicationActivity.cs
        // X:\jsc.svn\examples\java\android\LANBroadcastListener\LANBroadcastListener\ApplicationActivity.cs

        // X:\jsc.svn\core\ScriptCoreLibAndroidNDK\ScriptCoreLibAndroidNDK\SystemHeaders\sys\socket.cs

        static java.net.DatagramSocket try_new_DatagramSocket()
        {
            #region datagramSocket
            var datagramSocket = default(java.net.DatagramSocket);

            try
            {
                // http://developer.android.com/reference/java/net/DatagramSocket.html
                // Constructs a UDP datagram socket which is bound to any available port on the localhost.
                datagramSocket = new java.net.DatagramSocket();
            }
            catch
            {
                throw;
            }
            #endregion

            return(datagramSocket);
        }
Пример #5
0
        public Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
        {
            AddressFamily = addressFamily;
            SocketType    = socketType;
            ProtocolType  = protocolType;
                        #if cooper
            if ((AddressFamily != AddressFamily.InterNetwork) && (AddressFamily != AddressFamily.InterNetworkV6))
            {
                throw new Exception("Address family not supported on current platform");
            }

            switch (SocketType)
            {
            case SocketType.Stream:
                fHandle = new java.net.Socket();
                break;

            case SocketType.Dgram:
                fDgramHandle = new java.net.DatagramSocket();
                break;

            default:
                throw new Exception("Socket type not supported on current platform");
            }
                        #else
                        #if posix || toffee || darwin
            fHandle = rtl.socket((rtl.int32_t)addressFamily, (rtl.int32_t)socketType, (rtl.int32_t)protocolType);
                        #else
            fHandle = rtl.__Global.socket((rtl.INT)addressFamily, (rtl.INT)socketType, (rtl.INT)protocolType);
                        #endif

            if (fHandle < 0)
            {
                throw new Exception("Error creating socket");
            }
                        #endif
        }
Пример #6
0
        public __UdpClient(java.net.DatagramSocket datagramSocket)
        {
            //var buffer = new sbyte[0x10000];
            var buffer = new sbyte[0x1000];

            //E/dalvikvm-heap(14366): Out of memory on a 1048592-byte allocation.
            //I/dalvikvm(14366): "Thread-4310" prio=5 tid=827 RUNNABLE


            #region vReceiveAsync
            this.vReceiveAsync = delegate
            {
                var c = new TaskCompletionSource <__UdpReceiveResult>();

                __Task.Run(
                    delegate
                {
                    // http://stackoverflow.com/questions/10808512/datagrampacket-equivalent
                    // http://tutorials.jenkov.com/java-networking/udp-datagram-sockets.html



                    var packet = new java.net.DatagramPacket(buffer, buffer.Length);

                    try
                    {
                        datagramSocket.receive(packet);


                        var xbuffer = new byte[packet.getLength()];


                        Array.Copy(
                            buffer, xbuffer,
                            xbuffer.Length
                            );

                        var x = new __UdpReceiveResult(
                            buffer:
                            xbuffer,

                            remoteEndPoint:
                            new __IPEndPoint(
                                new __IPAddress {
                            InternalAddress = packet.getAddress()
                        },
                                port: packet.getPort()
                                )
                            );

                        c.SetResult(x);
                    }
                    catch
                    {
                        // fault?
                    }
                }
                    );


                return(c.Task);
            };
            #endregion

            #region vSendAsync
            this.vSendAsync = (byte[] datagram, int bytes, string hostname, int port) =>
            {
                var c = new TaskCompletionSource <int>();
                __Task.Run(
                    delegate
                {
                    try
                    {
                        var a      = global::java.net.InetAddress.getByName(hostname);
                        var packet = new java.net.DatagramPacket(
                            (sbyte[])(object)datagram,
                            datagram.Length, a, port
                            );
                        datagramSocket.send(packet);
                        // retval tested?
                        c.SetResult(
                            packet.getLength()
                            );
                    }
                    catch
                    {
                        throw;
                    }
                }
                    );
                return(c.Task);
            };
            #endregion

            #region vSendAsync2
            this.vSendAsync2 = (byte[] datagram, int bytes, IPEndPoint endPoint) =>
            {
                var c = new TaskCompletionSource <int>();
                __Task.Run(
                    delegate
                {
                    try
                    {
                        var packet = new java.net.DatagramPacket(
                            (sbyte[])(object)datagram,
                            datagram.Length, (__IPAddress)endPoint.Address, endPoint.Port
                            );
                        datagramSocket.send(packet);
                        // retval tested?
                        c.SetResult(
                            packet.getLength()
                            );
                    }
                    catch
                    {
                        throw;
                    }
                }
                    );
                return(c.Task);
            };
            #endregion

            #region vClose
            this.vClose = delegate
            {
                try
                {
                    datagramSocket.close();
                }
                catch
                {
                }
            };
            #endregion
        }
Пример #7
0
 public static android.os.ParcelFileDescriptor fromDatagramSocket(java.net.DatagramSocket
                                                                  datagramSocket)
 {
     throw new System.NotImplementedException();
 }
        public void SelectionChanged(string Address)
        {
            // https://code.google.com/p/boxeeremote/wiki/AndroidUDP

            Console.WriteLine(
                "SelectionChanged " + new { Address }
                );



#if Android // MulticastSend
            int MulticastSend_c = 0;
            Action<string, string, string, string> MulticastSend = (string reason, string data, string preview, string nn) =>
            {
                /// http://www.daniweb.com/software-development/java/threads/424998/udp-client-server-in-java
                // http://docs.oracle.com/javase/tutorial/networking/datagrams/broadcasting.html

                MulticastSend_c++;

                //var n = c + " hello world";
                var message =
                    new XElement("string",
                        new XAttribute("reason", reason),
                        new XAttribute("c", "" + MulticastSend_c),
                        new XAttribute("preview", preview),
                        new XAttribute("n", nn),
                        data
                    ).ToString();

                Console.WriteLine(new { message });

                new Thread(
                    delegate()
                    {
                        try
                        {
                            var socket = new java.net.DatagramSocket(
                                new Random().Next(16000, 32000),
                                java.net.InetAddress.getByName(Address)
                            );



                            byte[] b = Encoding.UTF8.GetBytes(message.ToString());    //creates a variable b of type byte

                            var dgram = new java.net.DatagramPacket(
                                (sbyte[])(object)b,
                                b.Length,
                                java.net.InetAddress.getByName("239.1.2.3"),
                                40404);//sends the packet details, length of the packet,destination address and the port number as parameters to the DatagramPacket  

                            socket.send(dgram); //send the datagram packet from this port
                        }
                        catch
                        {
                            System.Console.WriteLine("server error");
                        }
                    }
                )
                {

                    Name = "server"
                }.Start();
            };

            MulticastSend(
                "",
                "Visit me at " + Address + ":" + 666,
                "",
                ""
            );
#endif


        }
Пример #9
0
        public __UdpClient(xConstructorArguments args)
        {
            //Console.WriteLine("enter __UdpClient ctor");


            // http://stackoverflow.com/questions/8558791/multicastsocket-vs-datagramsocket-in-broadcasting-to-multiple-clients
            // you must use MulticastSocket for receiving the multicasts; for sending them, again, you can use either DatagramSocket or MulticastSocket, and there is no difference in efficiency.

            //var buffer = new sbyte[0x10000];

            // X:\jsc.svn\market\synergy\javascript\chrome\chrome\BCLImplementation\System\Net\Sockets\UdpClient.cs
            //var buffer = new sbyte[0x1000];
            var buffer = new sbyte[MaxData];

            //E/dalvikvm-heap(14366): Out of memory on a 1048592-byte allocation.
            //I/dalvikvm(14366): "Thread-4310" prio=5 tid=827 RUNNABLE



            // tested by
            // X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorld\ApplicationActivity.cs

            #region vJoinMulticastGroup
            this.vJoinMulticastGroup = (IPAddress multicastAddr, IPAddress localAddress) =>
           {
               // http://developer.android.com/reference/java/net/InetSocketAddress.html
               // http://developer.android.com/reference/java/net/SocketAddress.html

               Console.WriteLine("enter vJoinMulticastGroup");
               // at this point we have to jump back in time and get a multicast socket.

               __IPAddress __multicastAddr = multicastAddr;
               __IPAddress __localAddress = localAddress;

               __NetworkInterface nic = __localAddress.InternalNetworkInterface;

               // X:\jsc.svn\examples\java\android\LANBroadcastListener\LANBroadcastListener\ApplicationActivity.cs
               // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs

               try
               {
                   args.xMulticastSocket.joinGroup(
                       new java.net.InetSocketAddress(
                            __multicastAddr.InternalAddress,
                            args.port
                       ),

                       nic
                   );
               }
               catch
               {
                   throw;
               }

           };
            #endregion


            #region vReceiveAsync
            this.vReceiveAsync = delegate
            {
                var c = new TaskCompletionSource<__UdpReceiveResult>();

                __Task.Run(
                    delegate
                    {
                        // http://stackoverflow.com/questions/10808512/datagrampacket-equivalent
                        // http://tutorials.jenkov.com/java-networking/udp-datagram-sockets.html


                        // tested by?
                        var packet = new java.net.DatagramPacket(buffer, buffer.Length);

                        try
                        {
                            args.xDatagramSocket.receive(packet);


                            var xbuffer = new byte[packet.getLength()];


                            Array.Copy(
                                buffer, xbuffer,
                                xbuffer.Length
                            );

                            var x = new __UdpReceiveResult(
                                buffer:
                                    xbuffer,

                                remoteEndPoint:
                                    new __IPEndPoint(
                                        new __IPAddress { InternalAddress = packet.getAddress() },
                                        port: packet.getPort()
                                    )
                            );

                            c.SetResult(x);
                        }
                        catch
                        {
                            // fault? 
                        }
                    }
                );


                return c.Task;
            };
            #endregion

            //Console.WriteLine("enter __UdpClient before this.Client");

            this.Client = new __Socket
           {
               #region vBind
               vBind = (EndPoint localEP) =>
               {
                   // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150721/ovroculus360photoshud

                   try
                   {
                       Console.WriteLine("enter __UdpClient vBind " + new { args.xDatagramSocket, localEP });


                       var v4 = localEP as IPEndPoint;
                       if (v4 != null)
                       {
                           __IPAddress v4a = v4.Address;



                           // http://developer.android.com/reference/java/net/InetSocketAddress.html
                           var x = new java.net.InetSocketAddress(v4a.InternalAddress, v4.Port);

                           Console.WriteLine("before __UdpClient vBind " + new { v4a.InternalAddress, v4.Port });

                           // Z:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\UDPWindWheel\Program.cs
                           // is this the first bind?

                           if (args.xDatagramSocket == null)
                           {
                               var xDatagramSocket = new java.net.DatagramSocket(v4.Port);

                               args.vDatagramSocket = () => xDatagramSocket;
                           }
                           else
                           {
                               args.xDatagramSocket.bind(x);
                           }
                       }

                   }
                   catch (Exception err)
                   {
                       Console.WriteLine("err __UdpClient vBind " + new { err.Message, err.StackTrace });
                       //throw;


                       throw new InvalidOperationException();
                   }
               }
               #endregion
           };



            //Console.WriteLine("enter __UdpClient after this.Client " + new { this.Client });


            #region vSend
            this.vSend = (byte[] datagram, int bytes, string hostname, int port) =>
            {
                //I/System.Console(22987): 59cb:0001 about to Send
                //I/System.Console(22987): 59cb:0001 enter __UdpClient vSend
                //I/System.Console(22987): 59cb:0001 err __UdpClient vSend { Message = , StackTrace = android.os.NetworkOnMainThreadException
                //I/System.Console(22987):        at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
                //I/System.Console(22987):        at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:276)
                //I/System.Console(22987):        at libcore.io.IoBridge.sendto(IoBridge.java:513)
                //I/System.Console(22987):        at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:184)
                //I/System.Console(22987):        at java.net.DatagramSocket.send(DatagramSocket.java:305)
                //I/System.Console(22987):        at ScriptCoreLibJava.BCLImplementation.System.Net.Sockets.__UdpClient___c__DisplayClass12.__ctor_b__6(__UdpClient___c__DisplayClass12.java:109)

                var t = this.vSendAsync(datagram, bytes, hostname, port);



                return t.Result;
            };
            #endregion


            #region vSendAsync
            this.vSendAsync = (byte[] datagram, int bytes, string hostname, int port) =>
            {
                var c = new TaskCompletionSource<int>();
                __Task.Run(
                    delegate
                    {
                        try
                        {
                            var a = global::java.net.InetAddress.getByName(hostname);
                            var packet = new java.net.DatagramPacket(
                                (sbyte[])(object)datagram,
                                bytes, a, port
                            );
                            args.xDatagramSocket.send(packet);
                            // retval tested?
                            c.SetResult(
                                packet.getLength()
                            );
                        }
                        catch
                        {
                            throw;
                        }
                    }
                );
                return c.Task;
            };
            #endregion

            #region vSendAsync2
            this.vSendAsync2 = (byte[] datagram, int bytes, IPEndPoint endPoint) =>
            {
                var c = new TaskCompletionSource<int>();
                __Task.Run(
                    delegate
                    {
                        try
                        {
                            var packet = new java.net.DatagramPacket(
                                (sbyte[])(object)datagram,
                                bytes, (__IPAddress)endPoint.Address, endPoint.Port
                            );
                            args.xDatagramSocket.send(packet);
                            // retval tested?
                            c.SetResult(
                                packet.getLength()
                            );
                        }
                        catch
                        {
                            throw;
                        }
                    }
                );
                return c.Task;
            };
            #endregion

            #region vClose
            this.vClose = delegate
            {
                try
                {
                    args.xDatagramSocket.close();
                }
                catch
                {
                }
            };
            #endregion

        }
Пример #10
0
            public static xConstructorArguments Of(int port)
            {
                // X:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPFloats\ChromeUDPFloats\Application.cs

                var xMulticastSocket = default(java.net.MulticastSocket);
                var xDatagramSocket = default(java.net.DatagramSocket);

                // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs
                return new xConstructorArguments
                {
                    port = port,

                    vMulticastSocket = delegate
                    {
                        if (xMulticastSocket != null)
                            return xMulticastSocket;


                        #region datagramSocket

                        try
                        {
                            xMulticastSocket = new java.net.MulticastSocket(port);
                            xDatagramSocket = xMulticastSocket;
                        }
                        catch
                        {
                            throw;
                        }
                        #endregion

                        return xMulticastSocket;
                    },

                    vDatagramSocket = delegate
                    {
                        if (xDatagramSocket != null)
                            return xDatagramSocket;

                        try
                        {
                            xDatagramSocket = new java.net.DatagramSocket(port);
                        }
                        catch
                        {
                            throw;
                        }

                        return xDatagramSocket;
                    }
                };
            }
Пример #11
0
            public static xConstructorArguments Of(IPEndPoint e)
            {
                var xMulticastSocket = default(java.net.MulticastSocket);
                var xDatagramSocket = default(java.net.DatagramSocket);

                // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs
                return new xConstructorArguments
                {
                    vMulticastSocket = delegate
                    {
                        if (xMulticastSocket != null)
                            return xMulticastSocket;


                        #region datagramSocket

                        try
                        {
                            xMulticastSocket = new java.net.MulticastSocket(e.Port);
                            xDatagramSocket = xMulticastSocket;
                        }
                        catch
                        {
                            throw;
                        }
                        #endregion

                        return xMulticastSocket;
                    },

                    vDatagramSocket = delegate
                    {
                        if (xDatagramSocket != null)
                            return xDatagramSocket;

                        try
                        {
                            xDatagramSocket = new java.net.DatagramSocket(e.Port);
                        }
                        catch
                        {
                            throw;
                        }

                        return xDatagramSocket;
                    }
                };
            }
Пример #12
0
        public __UdpClient(xConstructorArguments args)
        {
            //Console.WriteLine("enter __UdpClient ctor");


            // http://stackoverflow.com/questions/8558791/multicastsocket-vs-datagramsocket-in-broadcasting-to-multiple-clients
            // you must use MulticastSocket for receiving the multicasts; for sending them, again, you can use either DatagramSocket or MulticastSocket, and there is no difference in efficiency.

            //var buffer = new sbyte[0x10000];

            // X:\jsc.svn\market\synergy\javascript\chrome\chrome\BCLImplementation\System\Net\Sockets\UdpClient.cs
            //var buffer = new sbyte[0x1000];
            var buffer = new sbyte[MaxData];

            //E/dalvikvm-heap(14366): Out of memory on a 1048592-byte allocation.
            //I/dalvikvm(14366): "Thread-4310" prio=5 tid=827 RUNNABLE



            // tested by
            // X:\jsc.svn\examples\java\android\vr\OVRMyCubeWorldNDK\OVRMyCubeWorld\ApplicationActivity.cs

            #region vJoinMulticastGroup
            this.vJoinMulticastGroup = (IPAddress multicastAddr, IPAddress localAddress) =>
            {
                // http://developer.android.com/reference/java/net/InetSocketAddress.html
                // http://developer.android.com/reference/java/net/SocketAddress.html

                Console.WriteLine("enter vJoinMulticastGroup");
                // at this point we have to jump back in time and get a multicast socket.

                __IPAddress __multicastAddr = multicastAddr;
                __IPAddress __localAddress  = localAddress;

                __NetworkInterface nic = __localAddress.InternalNetworkInterface;

                // X:\jsc.svn\examples\java\android\LANBroadcastListener\LANBroadcastListener\ApplicationActivity.cs
                // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs

                try
                {
                    args.xMulticastSocket.joinGroup(
                        new java.net.InetSocketAddress(
                            __multicastAddr.InternalAddress,
                            args.port
                            ),

                        nic
                        );
                }
                catch
                {
                    throw;
                }
            };
            #endregion


            #region vReceiveAsync
            this.vReceiveAsync = delegate
            {
                var c = new TaskCompletionSource <__UdpReceiveResult>();

                __Task.Run(
                    delegate
                {
                    // http://stackoverflow.com/questions/10808512/datagrampacket-equivalent
                    // http://tutorials.jenkov.com/java-networking/udp-datagram-sockets.html


                    // tested by?
                    var packet = new java.net.DatagramPacket(buffer, buffer.Length);

                    try
                    {
                        args.xDatagramSocket.receive(packet);


                        var xbuffer = new byte[packet.getLength()];


                        Array.Copy(
                            buffer, xbuffer,
                            xbuffer.Length
                            );

                        var x = new __UdpReceiveResult(
                            buffer:
                            xbuffer,

                            remoteEndPoint:
                            new __IPEndPoint(
                                new __IPAddress {
                            InternalAddress = packet.getAddress()
                        },
                                port: packet.getPort()
                                )
                            );

                        c.SetResult(x);
                    }
                    catch
                    {
                        // fault?
                    }
                }
                    );


                return(c.Task);
            };
            #endregion

            //Console.WriteLine("enter __UdpClient before this.Client");

            this.Client = new __Socket
            {
                #region vBind
                vBind = (EndPoint localEP) =>
                {
                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150721/ovroculus360photoshud

                    try
                    {
                        Console.WriteLine("enter __UdpClient vBind " + new { args.xDatagramSocket, localEP });


                        var v4 = localEP as IPEndPoint;
                        if (v4 != null)
                        {
                            __IPAddress v4a = v4.Address;



                            // http://developer.android.com/reference/java/net/InetSocketAddress.html
                            var x = new java.net.InetSocketAddress(v4a.InternalAddress, v4.Port);

                            Console.WriteLine("before __UdpClient vBind " + new { v4a.InternalAddress, v4.Port });

                            // Z:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\UDPWindWheel\Program.cs
                            // is this the first bind?

                            if (args.xDatagramSocket == null)
                            {
                                var xDatagramSocket = new java.net.DatagramSocket(v4.Port);

                                args.vDatagramSocket = () => xDatagramSocket;
                            }
                            else
                            {
                                args.xDatagramSocket.bind(x);
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        Console.WriteLine("err __UdpClient vBind " + new { err.Message, err.StackTrace });
                        //throw;


                        throw new InvalidOperationException();
                    }
                }
                #endregion
            };



            //Console.WriteLine("enter __UdpClient after this.Client " + new { this.Client });


            #region vSend
            this.vSend = (byte[] datagram, int bytes, string hostname, int port) =>
            {
                //I/System.Console(22987): 59cb:0001 about to Send
                //I/System.Console(22987): 59cb:0001 enter __UdpClient vSend
                //I/System.Console(22987): 59cb:0001 err __UdpClient vSend { Message = , StackTrace = android.os.NetworkOnMainThreadException
                //I/System.Console(22987):        at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
                //I/System.Console(22987):        at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:276)
                //I/System.Console(22987):        at libcore.io.IoBridge.sendto(IoBridge.java:513)
                //I/System.Console(22987):        at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:184)
                //I/System.Console(22987):        at java.net.DatagramSocket.send(DatagramSocket.java:305)
                //I/System.Console(22987):        at ScriptCoreLibJava.BCLImplementation.System.Net.Sockets.__UdpClient___c__DisplayClass12.__ctor_b__6(__UdpClient___c__DisplayClass12.java:109)

                var t = this.vSendAsync(datagram, bytes, hostname, port);



                return(t.Result);
            };
            #endregion


            #region vSendAsync
            this.vSendAsync = (byte[] datagram, int bytes, string hostname, int port) =>
            {
                var c = new TaskCompletionSource <int>();
                __Task.Run(
                    delegate
                {
                    try
                    {
                        var a      = global::java.net.InetAddress.getByName(hostname);
                        var packet = new java.net.DatagramPacket(
                            (sbyte[])(object)datagram,
                            bytes, a, port
                            );
                        args.xDatagramSocket.send(packet);
                        // retval tested?
                        c.SetResult(
                            packet.getLength()
                            );
                    }
                    catch
                    {
                        throw;
                    }
                }
                    );
                return(c.Task);
            };
            #endregion

            #region vSendAsync2
            this.vSendAsync2 = (byte[] datagram, int bytes, IPEndPoint endPoint) =>
            {
                var c = new TaskCompletionSource <int>();
                __Task.Run(
                    delegate
                {
                    try
                    {
                        var packet = new java.net.DatagramPacket(
                            (sbyte[])(object)datagram,
                            bytes, (__IPAddress)endPoint.Address, endPoint.Port
                            );
                        args.xDatagramSocket.send(packet);
                        // retval tested?
                        c.SetResult(
                            packet.getLength()
                            );
                    }
                    catch
                    {
                        throw;
                    }
                }
                    );
                return(c.Task);
            };
            #endregion

            #region vClose
            this.vClose = delegate
            {
                try
                {
                    args.xDatagramSocket.close();
                }
                catch
                {
                }
            };
            #endregion
        }