コード例 #1
0
ファイル: Socket.cs プロジェクト: pavadik/internetpack
        private new void Dispose()
        {
                        #if cooper
            if (!fIsServer)
            {
                fHandle.close();
            }
            else
            {
                fServerHandle.close();
            }
                        #else
                        #if posix || toffee || darwin
            if (rtl.close(fHandle) != 0)
            {
                throw new Exception("Error closing socket");
            }
                        #else
            if (rtl.closesocket(fHandle) != 0)
            {
                throw new Exception("Error closing socket");
            }
                        #endif
                        #endif

            Connected = false;
        }
コード例 #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
        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
            }
        }
コード例 #4
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();
         }
     }
 }
コード例 #5
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
			}
		}