コード例 #1
0
        public void Listen_internal(int backlog, out int error)
        {
            error = 0;

            if (jSocket == null || !jSocket.isBound())
            {
                error = 10022;                 //WSAEINVAL (Invalid argument)
                return;
            }

            if (jSocket.isConnected() || jSocketChannel.isConnectionPending())
            {
                error = 10056;                 //WSAEISCONN (Socket is already connected)
                return;
            }

            bool blockMode = jSocketChannel.isBlocking();
            bool reuseAddr = jSocket.getReuseAddress();

            try
            {
                jSocket.close();
            }
            catch (Exception e)
            {
#if DEBUG
                Console.WriteLine("Caught exception during Listen_internal close old jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
            }

            try
            {
                jSocketChannel.close();
            }
            catch (Exception e)
            {
#if DEBUG
                Console.WriteLine("Caught exception during Listen_internal close old jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
            }

            jSocket        = null;
            jSocketChannel = null;

            try
            {
                jServerSocketChannel = java.nio.channels.ServerSocketChannel.open();
                jServerSocket        = jServerSocketChannel.socket();
                jServerSocket.bind(jTempLocalSocketAddress, backlog);
                jServerSocketChannel.configureBlocking(blockMode);
                jServerSocket.setReuseAddress(reuseAddr);
            }
            catch (Exception e)
            {
                error = 10048;                 //WSAEADDRINUSE (Address already in use)
#if DEBUG
                Console.WriteLine("Caught exception during Listen_internal create server socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
            }
        }
コード例 #2
0
        public void Close_internal(out int error)
        {
            error = 0;

            if (jServerSocket != null)
            {
                try
                {
                    jServerSocket.close();
                }
                catch (Exception e)
                {
                    error = 10022;                     //WSAEINVAL (Invalid argument)
#if DEBUG
                    Console.WriteLine("Caught exception during Close_internal jServerSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
                }
                try
                {
                    jServerSocketChannel.close();
                }
                catch (Exception e)
                {
                    error = 10022;                     //WSAEINVAL (Invalid argument)
#if DEBUG
                    Console.WriteLine("Caught exception during Close_internal jServerSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
                }
                jServerSocket        = null;
                jServerSocketChannel = null;
            }
            else if (jSocket != null)
            {
                try
                {
                    jSocket.close();
                }
                catch (Exception e)
                {
                    error = 10022;                     //WSAEINVAL (Invalid argument)
#if DEBUG
                    Console.WriteLine("Caught exception during Close_internal jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
                }
                try
                {
                    jSocketChannel.close();
                }
                catch (Exception e)
                {
                    error = 10022;                     //WSAEINVAL (Invalid argument)
#if DEBUG
                    Console.WriteLine("Caught exception during Close_internal jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
                }
                jSocket        = null;
                jSocketChannel = null;
            }
        }
コード例 #3
0
 private Socket(rtl.SOCKET handle)
         #endif
 {
     fHandle = handle;
                 #if cooper
     fSocketInput  = fHandle.getInputStream();
     fSocketOutput = fHandle.getOutputStream();
                 #endif
 }
コード例 #4
0
ファイル: Util.cs プロジェクト: weimingtom/pap2
        internal static java.net.Socket createSocket(String host, int port, int timeout)
        {
            java.net.Socket socket  = null;
            String          message = "";

            if (timeout == 0)
            {
                try
                {
                    socket = new java.net.Socket(host, port);
                    return(socket);
                }
                catch (Exception e)
                {
                    message = e.ToString();
                    throw new JSchException(message);
                }
            }
            String _host = host;
            int    _port = port;

            java.net.Socket[] sockp         = new java.net.Socket[1];
            Thread            currentThread = Thread.CurrentThread;

            Exception[] ee = new Exception[1];
            message = "";
            createSocketRun runnable = new createSocketRun(sockp, ee, _host, _port);
            Thread          tmp      = new Thread(new ThreadStart(runnable.run));

            tmp.Name = "Opening Socket " + host;
            tmp.Start();
            try
            {
                tmp.Join(timeout);
                message = "timeout: ";
            }
            catch (ThreadInterruptedException eee)
            {
            }
            if (sockp[0] != null && sockp[0].isConnected())
            {
                socket = sockp[0];
            }
            else
            {
                message += "socket is not established";
                if (ee[0] != null)
                {
                    message = ee[0].ToString();
                }
                tmp.Interrupt();
                tmp = null;
                throw new JSchException(message);
            }
            return(socket);
        }
コード例 #5
0
 protected virtual void implAccept(java.net.Socket arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         @__env.CallVoidMethod(this.JvmHandle, global::java.net.ServerSocket._implAccept13752, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
     }
     else
     {
         @__env.CallNonVirtualVoidMethod(this.JvmHandle, global::java.net.ServerSocket.staticClass, global::java.net.ServerSocket._implAccept13752, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0));
     }
 }
コード例 #6
0
ファイル: SSLSocketFactory.cs プロジェクト: zffl/androidmono
 public virtual global::java.net.Socket connectSocket(java.net.Socket arg0, java.lang.String arg1, int arg2, java.net.InetAddress arg3, int arg4, [email protected] arg5)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallObjectMethod(this.JvmHandle, global::org.apache.http.conn.ssl.SSLSocketFactory._connectSocket16423, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg3), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg4), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg5))) as java.net.Socket);
     }
     else
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallNonVirtualObjectMethod(this.JvmHandle, global::org.apache.http.conn.ssl.SSLSocketFactory.staticClass, global::org.apache.http.conn.ssl.SSLSocketFactory._connectSocket16423, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg3), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg4), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg5))) as java.net.Socket);
     }
 }
コード例 #7
0
 bool org.apache.http.conn.scheme.SocketFactory.isSecure(java.net.Socket arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(@__env.CallBooleanMethod(this.JvmHandle, global::org.apache.http.conn.scheme.SocketFactory_._isSecure16419, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)));
     }
     else
     {
         return(@__env.CallNonVirtualBooleanMethod(this.JvmHandle, global::org.apache.http.conn.scheme.SocketFactory_.staticClass, global::org.apache.http.conn.scheme.SocketFactory_._isSecure16419, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0)));
     }
 }
コード例 #8
0
ファイル: SSLSocketFactory.cs プロジェクト: zffl/androidmono
 public override global::java.net.Socket createSocket(java.net.Socket arg0, java.lang.String arg1, int arg2, bool arg3)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallObjectMethod(this.JvmHandle, global::javax.net.ssl.SSLSocketFactory_._createSocket16045, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg3))) as java.net.Socket);
     }
     else
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallNonVirtualObjectMethod(this.JvmHandle, global::javax.net.ssl.SSLSocketFactory_.staticClass, global::javax.net.ssl.SSLSocketFactory_._createSocket16045, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg3))) as java.net.Socket);
     }
 }
コード例 #9
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void open()
 {
     lock (this)
     {
         if (this.isOpen())
         {
             return;
         }
         if (this.useSsl != null && this.useSsl)
         {
             if (this.sslContext != null)
             {
                 this.socket = this.sslContext.getSocketFactory().createSocket();
             }
             else
             {
                 this.socket = javax.net.ssl.SSLSocketFactory.getDefault().createSocket();
             }
         }
         else
         {
             this.socket = javax.net.SocketFactory.getDefault().createSocket();
         }
         string host = this.host != null ? this.host : ArangoDBConstants
                       .DEFAULT_HOST;
         int port = this.port != null ? this.port : ArangoDBConstants
                    .DEFAULT_PORT;
         if (LOGGER.isDebugEnabled())
         {
             LOGGER.debug(string.format("Open connection to addr=%s,port=%s", host, port));
         }
         this.socket.connect(new java.net.InetSocketAddress(host, port), this.timeout != null ? this.timeout
              : ArangoDBConstants.DEFAULT_TIMEOUT);
         this.socket.setKeepAlive(true);
         this.socket.setTcpNoDelay(true);
         if (LOGGER.isDebugEnabled())
         {
             LOGGER.debug(string.format("Connected to %s", this.socket));
         }
         this.outputStream = new java.io.BufferedOutputStream(this.socket.getOutputStream());
         this.inputStream  = this.socket.getInputStream();
         if (this.useSsl != null && this.useSsl)
         {
             if (LOGGER.isDebugEnabled())
             {
                 LOGGER.debug(string.format("Start Handshake on %s", this.socket));
             }
             ((javax.net.ssl.SSLSocket) this.socket).startHandshake();
         }
         this.sendProtocolHeader();
     }
 }
コード例 #10
0
ファイル: Socket.cs プロジェクト: pavadik/internetpack
        public void Connect(EndPoint remoteEP)
        {
            var lEndPoint = (IPEndPoint)remoteEP;

                        #if cooper
            var lAddress = java.net.InetAddress.getByAddress(lEndPoint.Address.GetAddressBytes());
            fHandle       = new java.net.Socket(lAddress, lEndPoint.Port);
            fSocketInput  = fHandle.getInputStream();
            fSocketOutput = fHandle.getOutputStream();
                        #else
            void *lPointer;
            int   lSize;
                        #if posix || toffee || darwin || android
            rtl.__struct_sockaddr_in  lIPv4;
            rtl.__struct_sockaddr_in6 lIPv6;
                        #if posix && !darwin && !android
            rtl.__CONST_SOCKADDR_ARG lSockAddr;
                        #else
            rtl.__struct_sockaddr lSockAddr;
                        #endif
                        #else
            rtl.SOCKADDR_IN lIPv4;
            sockaddr_in6    lIPv6;
                        #endif


            IPEndPointToNative(lEndPoint, out lIPv4, out lIPv6, out lPointer, out lSize);
            var lRes = 0;
                        #if posix && !darwin && !android
            lSockAddr.__sockaddr__ = (rtl.__struct_sockaddr *)lPointer;
            lRes = rtl.connect(fHandle, lSockAddr, lSize);
                        #elif toffee || darwin || android
            lRes = rtl.connect(fHandle, (rtl.__struct_sockaddr *)lPointer, lSize);
                        #else
            lRes = rtl.connect(fHandle, lPointer, lSize);
                        #endif
            if (lRes != 0)
            {
                throw new Exception("Error connecting socket");
            }
                        #endif

            Connected = true;
        }
コード例 #11
0
        public void Bind_internal(EndPoint sa, out int error)
        {
            error = 0;
            IPEndPoint addr = sa as IPEndPoint;

            if (addr == null)
            {
                error = 10044;                 //WSAESOCKTNOSUPPORT (Socket type not supported)
                return;
            }

            if (jSocket == null || jSocket.isBound() || jSocket.isConnected() || jSocketChannel.isConnectionPending())
            {
                error = 10022;                 //WSAEINVAL (Invalid argument)
                return;
            }

            try
            {
                // This code I need because a bug in the java.nio.channels.SocketAdapter, which
                // returns local port 0 if the socket is not connected (even if the socket is bound)
                // so I need temporary use regular socket (not channel socket) to bind it to the
                // local address and use this address in the LocalPoint property and to create the
                // actual client/server channel sockets
                // The bug #5076965 (SocketChannel does not report local address after binding to a wildcard )
                // See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5076965
                java.net.Socket jTempSocket = new java.net.Socket();
                jTempSocket.bind(new java.net.InetSocketAddress(java.net.InetAddress.getByName(addr.Address.ToString()),
                                                                addr.Port));
                jTempLocalSocketAddress = (java.net.InetSocketAddress)jTempSocket.getLocalSocketAddress();
                jTempSocket.close();
                jSocket.bind(jTempLocalSocketAddress);
            }
            catch (Exception e)
            {
                error = 10048;                 //WSAEADDRINUSE (Address already in use)
#if DEBUG
                Console.WriteLine("Caught exception during Bind_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
            }
        }
コード例 #12
0
ファイル: Util.cs プロジェクト: weimingtom/pap2
 public void run()
 {
     sockp[0] = null;
     try
     {
         sockp[0] = new java.net.Socket(_host, _port);
     }
     catch (Exception e)
     {
         ee[0] = e;
         if (sockp[0] != null && sockp[0].isConnected())
         {
             try
             {
                 sockp[0].close();
             }
             catch (Exception eee) {}
         }
         sockp[0] = null;
     }
 }
コード例 #13
0
ファイル: Socket.cs プロジェクト: pavadik/internetpack
        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
        }
コード例 #14
0
ファイル: Socket.cs プロジェクト: getcontext/CSSocketServer
 public void handleStream(java.net.Socket client)
 {
     try
     {
         setClient(client);
         OutputStream = new ObjectOutputStream(getClient().getOutputStream());
         InputStream  = new ObjectInputStream(getClient().getInputStream());
     }
     catch (IOException e)
     {
         e.printStackTrace();
     }
     finally
     {
         try
         { //try to close gracefully
             client.close();
         }
         catch (IOException e)
         {
             e.printStackTrace();
         }
     }
 }
コード例 #15
0
 public GHStreamSocketSSL(java.net.Socket sslSocket)
 {
     jSocket = sslSocket;
 }
コード例 #16
0
        // the alias name of a matching key or null if there are no matches.
        // Chooses an alias for the server side of an SSL connection to authenticate it with the specified public key type and certificate issuers.
        public override string chooseServerAlias(string keyType, java.security.Principal[] issuers, java.net.Socket socket)
        {
            if (keyType != "RSA")
            {
                return(null);
            }

            // chooseServerAlias { keyType = EC_EC }
            Console.WriteLine("chooseServerAlias " + new { keyType, StackTrace = new System.Diagnostics.StackTrace() });

            //if (issuers != null)
            //    foreach (var issuer in issuers)
            //    {
            //        Console.WriteLine("chooseServerAlias " + new { keyType, issuer });
            //    }

            // { aliasKey = 192.168.1.12, SerialNumber = c7ef5d7ff74627934e4f863f4a766a89, SimpleName = 192.168.1.12, Issuer = issuer }

            //return "192.168.1.12";
            return(alias);
        }
コード例 #17
0
ファイル: GHStreamSocket.jvm.cs プロジェクト: carrie901/mono
		public GHStreamSocket()
		{
			jSocketChannel = java.nio.channels.SocketChannel.open();
			jSocket = jSocketChannel.socket();
		}
コード例 #18
0
 public static ParcelFileDescriptor fromSocket(java.net.Socket socket)
 {
     return(null);
 }
コード例 #19
0
ファイル: Util.cs プロジェクト: itsbth/GLuaR
 internal static java.net.Socket createSocket(String host, int port, int timeout)
 {
     java.net.Socket socket=null;
     String message="";
     if(timeout==0)
     {
         try
         {
             socket=new java.net.Socket(host, port);
             return socket;
         }
         catch(Exception e)
         {
             message=e.ToString();
             throw new JSchException(message);
         }
     }
     String _host=host;
     int _port=port;
     java.net.Socket[] sockp=new java.net.Socket[1];
     Thread currentThread=Thread.CurrentThread;
     Exception[] ee=new Exception[1];
     message="";
     createSocketRun runnable = new createSocketRun(sockp, ee, _host, _port);
     Thread tmp=new Thread(new ThreadStart(runnable.run));
     tmp.Name = "Opening Socket "+host;
     tmp.Start();
     try
     {
         tmp.Join(timeout);
         message="timeout: ";
     }
     catch(ThreadInterruptedException eee)
     {
     }
     if(sockp[0]!=null && sockp[0].isConnected())
     {
         socket=sockp[0];
     }
     else
     {
         message+="socket is not established";
         if(ee[0]!=null)
         {
             message=ee[0].ToString();
         }
         tmp.Interrupt();
         tmp=null;
         throw new JSchException(message);
     }
     return socket;
 }
コード例 #20
0
ファイル: SSLSocketFactory.cs プロジェクト: zffl/androidmono
 public abstract global::java.net.Socket createSocket(java.net.Socket arg0, java.lang.String arg1, int arg2, bool arg3);
コード例 #21
0
ファイル: Socket.cs プロジェクト: pavadik/internetpack
 private Socket(int handle)
 {
     fHandle = handle;
 }
コード例 #22
0
		public GHStreamSocketSSL(java.net.Socket sslSocket)
		{
			jSocket = sslSocket;
		}
コード例 #23
0
 public GHStreamSocket(java.nio.channels.SocketChannel socketChannel)
 {
     jSocketChannel = socketChannel;
     jSocket        = jSocketChannel.socket();
 }
コード例 #24
0
ファイル: Socket.cs プロジェクト: pavadik/internetpack
 private Socket(java.net.Socket handle)
 {
     fHandle       = handle;
     fSocketInput  = fHandle.getInputStream();
     fSocketOutput = fHandle.getOutputStream();
 }
コード例 #25
0
 public static global::android.os.ParcelFileDescriptor fromSocket(java.net.Socket arg0)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallStaticObjectMethod(android.os.ParcelFileDescriptor.staticClass, global::android.os.ParcelFileDescriptor._fromSocket6644, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0))) as android.os.ParcelFileDescriptor);
 }
コード例 #26
0
ファイル: GHStreamSocket.jvm.cs プロジェクト: carrie901/mono
		public void Listen_internal(int backlog, out int error)
		{
			error = 0;

			if (jSocket == null || !jSocket.isBound())
			{
				error = 10022; //WSAEINVAL (Invalid argument)
				return;
			}

			if (jSocket.isConnected() || jSocketChannel.isConnectionPending())
			{
				error = 10056; //WSAEISCONN (Socket is already connected)
				return;
			}

			bool blockMode = jSocketChannel.isBlocking();
			bool reuseAddr = jSocket.getReuseAddress();

			try
			{
				jSocket.close();
			}
			catch (Exception e)
			{
#if DEBUG
				Console.WriteLine("Caught exception during Listen_internal close old jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}

			try
			{
				jSocketChannel.close();
			}
			catch (Exception e)
			{
#if DEBUG
				Console.WriteLine("Caught exception during Listen_internal close old jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}

			jSocket = null;
			jSocketChannel = null;

			try
			{
				jServerSocketChannel = java.nio.channels.ServerSocketChannel.open();
				jServerSocket = jServerSocketChannel.socket();
				jServerSocket.bind(jTempLocalSocketAddress, backlog);
				jServerSocketChannel.configureBlocking(blockMode);
				jServerSocket.setReuseAddress(reuseAddr);
			}
			catch (Exception e)
			{
				error = 10048; //WSAEADDRINUSE (Address already in use)
#if DEBUG
				Console.WriteLine("Caught exception during Listen_internal create server socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}
		}
コード例 #27
0
ファイル: GHStreamSocket.jvm.cs プロジェクト: carrie901/mono
		public GHStreamSocket(java.nio.channels.SocketChannel socketChannel)
		{
			jSocketChannel = socketChannel;
			jSocket = jSocketChannel.socket();
		}
コード例 #28
0
        public override string chooseClientAlias(string[] keyType, java.security.Principal[] issuers, java.net.Socket socket)
        {
            Console.WriteLine("chooseClientAlias " + new { StackTrace = new System.Diagnostics.StackTrace() });

            if (keyType != null)
            {
                foreach (var keyType0 in keyType)
                {
                    Console.WriteLine("chooseClientAlias " + new { keyType0 });
                }
            }


            if (issuers != null)
            {
                foreach (var issuer in issuers)
                {
                    Console.WriteLine("chooseClientAlias " + new { issuer });
                }
            }


            // client does not have an alies does it?
            return(this.InternalX509KeyManager.chooseClientAlias(keyType, issuers, socket));
        }
コード例 #29
0
ファイル: Socket.cs プロジェクト: pavadik/internetpack
 private Socket(rtl.SOCKET handle)
 {
     fHandle = handle;
 }
コード例 #30
0
ファイル: Util.cs プロジェクト: itsbth/GLuaR
 public void run()
 {
     sockp[0]=null;
     try
     {
         sockp[0]=new java.net.Socket(_host, _port);
     }
     catch(Exception e)
     {
         ee[0]=e;
         if(sockp[0]!=null && sockp[0].isConnected())
         {
             try
             {
                 sockp[0].close();
             }
             catch(Exception eee){}
         }
         sockp[0]=null;
     }
 }
コード例 #31
0
 public GHStreamSocket()
 {
     jSocketChannel = java.nio.channels.SocketChannel.open();
     jSocket        = jSocketChannel.socket();
 }
コード例 #32
0
		public void Close_internal(out int error)
		{
			error = 0;

			try
			{
				if (jSocket != null)
				{
					jSocket.close();
					jSocket = null;
				}
			}
			catch (Exception e)
			{
				error = 10022; //WSAEINVAL (Invalid argument)
#if DEBUG
				Console.WriteLine("Caught exception during Close_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}
		}
コード例 #33
0
        public GHSocket ChangeToSSL(EndPoint remote_end)
        {
            if (jSocket == null)
            {
                throw new InvalidOperationException("The underlying socket is null");
            }

            if (!jSocketChannel.isBlocking())
            {
                throw new NotImplementedException("The SSL Socket for non-blocking mode is not supported");
            }

            SSLSocketFactory factory = getSSLSocketFactory();

            if (factory == null)
            {
                throw new ApplicationException("Can't get SSL Socket Factory");
            }

            int err;

            // The problem with local address, when I closed the socket and try to create the new one
            // bounded to the given local address, I receive exception "Address already in use"
            IPEndPoint localEndPoint = null;
//			IPEndPoint localEndPoint = (IPEndPoint) LocalEndPoint_internal(out err);
//			if (err != 0)
//				localEndPoint = null;

            IPEndPoint remoteEndPoint = remote_end as IPEndPoint;

            if (remoteEndPoint == null)
            {
                remoteEndPoint = (IPEndPoint)RemoteEndPoint_internal(out err);
                if (err != 0)
                {
                    remoteEndPoint = null;
                }
            }

            java.net.Socket sslSocket = null;
            try
            {
                if (remoteEndPoint != null)
                {
                    if (localEndPoint != null)
                    {
                        sslSocket = factory.createSocket(
                            java.net.InetAddress.getByName(remoteEndPoint.Address.ToString()),
                            remoteEndPoint.Port,
                            java.net.InetAddress.getByName(localEndPoint.Address.ToString()),
                            localEndPoint.Port);
                    }
                    else
                    {
                        sslSocket = factory.createSocket(
                            jSocket,
                            remoteEndPoint.Address.ToString(),
                            remoteEndPoint.Port,
                            false);
                    }

                    if (sslSocket != null)
                    {
                        String[] protocols = { "TLSv1", "SSLv3" };
                        ((SSLSocket)sslSocket).setUseClientMode(true);
                        ((SSLSocket)sslSocket).startHandshake();
                    }
                }
                else
                {
                    sslSocket = factory.createSocket();
                }
            }
            catch (Exception e)
            {
                sslSocket = null;
#if DEBUG
                Console.WriteLine("Can't create SSL Socket, the exception is {0}, {1}", e.GetType(), e.Message);
#endif
            }

            if (sslSocket == null)
            {
//				throw new ApplicationException("Can't create SSL Socket");
                // it is important to the Socket class to distinguish if the underlying
                // handle (GHSocket) is still valid and can be used as non-SSL, or it is already
                // closed by this function and can't be used any more.
                return(null);
            }

/*
 *                      string[] arr = ((SSLSocket)sslSocket).getEnabledProtocols();
 *                      if (arr != null)
 *                      {
 *                              foreach (string s in arr)
 *                                      Console.WriteLine("s:"+s);
 *                      }
 *                      string [] arr1 = ((SSLSocket)sslSocket).getEnabledCipherSuites();
 *                      if (arr1 != null)
 *                      {
 *                              foreach (string s in arr1)
 *                                      Console.WriteLine("s:"+s);
 *                      }
 */

            return(new GHStreamSocketSSL(sslSocket));
        }
コード例 #34
0
 public static android.os.ParcelFileDescriptor fromSocket(java.net.Socket socket)
 {
     throw new System.NotImplementedException();
 }
コード例 #35
0
 global::java.net.Socket org.apache.http.conn.scheme.LayeredSocketFactory.createSocket(java.net.Socket arg0, java.lang.String arg1, int arg2, bool arg3)
 {
     global::MonoJavaBridge.JNIEnv @__env = global::MonoJavaBridge.JNIEnv.ThreadEnv;
     if (!IsClrObject)
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallObjectMethod(this.JvmHandle, global::org.apache.http.conn.scheme.LayeredSocketFactory_._createSocket16396, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg3))) as java.net.Socket);
     }
     else
     {
         return(global::MonoJavaBridge.JavaBridge.WrapJavaObject(@__env.CallNonVirtualObjectMethod(this.JvmHandle, global::org.apache.http.conn.scheme.LayeredSocketFactory_.staticClass, global::org.apache.http.conn.scheme.LayeredSocketFactory_._createSocket16396, global::MonoJavaBridge.JavaBridge.ConvertToValue(arg0), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg1), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg2), global::MonoJavaBridge.JavaBridge.ConvertToValue(arg3))) as java.net.Socket);
     }
 }
コード例 #36
0
 private Socket(java.net.Socket handle)
コード例 #37
0
ファイル: GHStreamSocket.jvm.cs プロジェクト: carrie901/mono
		public void Bind_internal(EndPoint sa, out int error)
		{
			error = 0;
			IPEndPoint addr = sa as IPEndPoint;
			if (addr == null)
			{
				error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)
				return;
			}

			if (jSocket == null || jSocket.isBound() || jSocket.isConnected() || jSocketChannel.isConnectionPending())
			{
				error = 10022; //WSAEINVAL (Invalid argument)
				return;
			}

			try
			{
				// This code I need because a bug in the java.nio.channels.SocketAdapter, which 
				// returns local port 0 if the socket is not connected (even if the socket is bound)
				// so I need temporary use regular socket (not channel socket) to bind it to the 
				// local address and use this address in the LocalPoint property and to create the 
				// actual client/server channel sockets
				// The bug #5076965 (SocketChannel does not report local address after binding to a wildcard )
				// See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5076965
				java.net.Socket jTempSocket = new java.net.Socket();
				jTempSocket.bind(new java.net.InetSocketAddress(java.net.InetAddress.getByName(addr.Address.ToString()),
									                        addr.Port));
				jTempLocalSocketAddress = (java.net.InetSocketAddress)jTempSocket.getLocalSocketAddress();
				jTempSocket.close();
				jSocket.bind(jTempLocalSocketAddress);
			}
			catch (Exception e)
			{
				error = 10048; //WSAEADDRINUSE (Address already in use)
#if DEBUG
				Console.WriteLine("Caught exception during Bind_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}
		}