Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
   * JBoss, Home of Professional Open Source
   * Copyright 2005, JBoss Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  
  /*
   * Created on Jul 22, 2005
   */
  
  package org.jboss.remoting.transport.multiplex;
  
  import  org.jboss.logging.Logger;
  
  import java.net.Socket;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Set;

VirtualSocket represents an endpoint on a virtual connection created by the Multiplex system. It extends java.net.Socket and reimplements nearly all of the methods in java.net.Socket. For information about method behavior, please see the java.net.Socket javadoc. For more information about the nature of virtual sockets, please see the Multiplex documentation at the labs.jboss.org web site.

Copyright (c) 2005

Deprecated:
As of release 2.4.0 the multiplex transport will no longer be actively supported.
Author(s):
Ron Sigal
  
  public class VirtualSocket extends Socket
  {
     protected static final Logger log = Logger.getLogger(VirtualSocket.class);
     protected static Thread closingThread;
  
     private Map configuration = new HashMap();
     private MultiplexingManager manager;
     private Protocol protocol;
     private Socket actualSocket;
     private SocketId remoteSocketId;
     private SocketId localSocketId;
     private Set disconnectListeners = new HashSet();
  
     private boolean bound = false;
     private boolean closed = false;
     private boolean connected = false;
     private boolean inputShutdown = false;
     private boolean outputShutdown = false;
     private boolean receivedDisconnectMessage = false;
  
     private int     timeout;
     private Socket  dummySocket;
  
     private boolean functional = true;
  
     private boolean trace;
     private boolean debug;
     private boolean info;


   
A class that implements DisconnectListener can register to be notified if the remote peer of this VirtualSocket has disconnected.
 
    public interface DisconnectListener
    {
       void notifyDisconnected(VirtualSocket virtualSocket);
    }
 
 
    public VirtualSocket(MultiplexingManager managerSocketId remoteSocketIdMap configurationthrows IOException
    {
       this. = manager;
       this. = manager.getSocket();
       this. = remoteSocketId;
       this..putAll(configuration);
        = manager.getProtocol();
        = new SocketId();
        = manager.registerSocket(this);
 //      outputStream = new MultiplexingOutputStream(manager, this, remoteSocketId);
        = manager.getAnOutputStream(thisremoteSocketId);
        = true;
        = true;
 
        = .isTraceEnabled();
        = .isDebugEnabled();
        = .isInfoEnabled();
       if (.debug("created virtual socket on port: " + .getPort());
    }
 
 
    public VirtualSocket(Map configuration)
    {
       this..putAll(configuration);
    }
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 ///           The following constructors duplicate those of the parent class Socket           '///
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
See superclass javadoc.
 
    public VirtualSocket()
    {
       .debug("created unbound virtual socket");
    }


See superclass javadoc.
 
    public VirtualSocket(String hostint portthrows UnknownHostExceptionIOException
    {
       InetSocketAddress address = null;
 
       if (host == null)
          address = new InetSocketAddress(InetAddress.getByName(null), port);
       else
          address = new InetSocketAddress(hostport);
 
       connect(address);
       if (.debug("created virtual socket on port: " + .getPort());
    }


See superclass javadoc.

Parameters:
host
port
stream
Throws:
java.io.IOException
 
    public VirtualSocket(String hostint portboolean streamthrows IOException
    {
       if (!stream)
       {
          throw new SocketException("Deprecated: use DataGramSocket instead of stream = false");
       }
 
       InetSocketAddress address = null;
 
       if (host == null)
          address = new InetSocketAddress(InetAddress.getByName(null), port);
       else
          address = new InetSocketAddress(hostport);
 
       connect(address);
       if (.debug("created virtual socket on port: " + .getPort());
    }


See superclass javadoc.

Parameters:
address
port
Throws:
java.io.IOException
 
    public VirtualSocket(InetAddress addressint portthrows IOException
    {
       connect(new InetSocketAddress(addressport));
       if (.debug("created virtual socket on port: " + .getPort());
    }


See superclass javadoc.

Parameters:
host
port
stream
Throws:
java.io.IOException
 
    public VirtualSocket(InetAddress hostint portboolean streamthrows IOException
    {
       if (!stream)
       {
          throw new SocketException("Deprecated: use DataGramSocket instead of stream = false");
       }
 
       connect(new InetSocketAddress(hostport));
       if (.debug("created virtual socket on port: " + .getPort());
    }


This constuctor is not implemented.

Parameters:
impl
Throws:
java.net.SocketException in all cases
 
    public VirtualSocket(SocketImpl implthrows SocketException
    {
       throw new SocketException("VirtualSocket does not use SocketImpl");
    }


See superclass javadoc.

Parameters:
host
port
localAddr
localPort
Throws:
java.io.IOException
 
    public VirtualSocket(String hostint portInetAddress localAddrint localPortthrows IOException
    {
       this(InetAddress.getByName(host), portlocalAddrlocalPort);
    }


See superclass javadoc.

Parameters:
address
port
localAddr
localPort
Throws:
java.io.IOException
 
    public VirtualSocket(InetAddress addressint portInetAddress localAddrint localPortthrows IOException
    {
       this();
       connect(new InetSocketAddress(addressport), new InetSocketAddress(localAddrlocalPort), 0);
       if (.debug("created virtual socket on port: " + .getPort());
    }
 
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 ///                     The following methods are required of all Socket's                    '///
 //////////////////////////////////////////////////////////////////////////////////////////////////
 

   
public methods in Socket class ok: public void connect(SocketAddress endpoint) throws IOException; ok: public void connect(SocketAddress endpoint, int timeout) throws IOException; ok: public void bind(SocketAddress bindpoint) throws IOException; ok: public InetAddress getInetAddress(); ok: public InetAddress getLocalAddress(); ok: public int getPort(); ok: public int getLocalPort(); ok: public SocketAddress getRemoteSocketAddress(); ok: public SocketAddress getLocalSocketAddress(); ok: public SocketChannel getChannel(); ok: public InputStream getInputStream() throws IOException; ok: public OutputStream getOutputStream() throws IOException; ok: public void setTcpNoDelay(boolean on) throws SocketException; ok: public boolean getTcpNoDelay() throws SocketException; ok: public void setSoLinger(boolean on, int linger) throws SocketException; ok: public int getSoLinger() throws SocketException; ok: public void sendUrgentData(int data) throws IOException; ok: public void setOOBInline(boolean on) throws SocketException; ok: public boolean getOOBInline() throws SocketException; ok: public void setSoTimeout(int timeout) throws SocketException; ok: public int getSoTimeout() throws SocketException; ok: public void setSendBufferSize(int size) throws SocketException; ok: public int getSendBufferSize() throws SocketException; ok: public void setReceiveBufferSize(int size) throws SocketException; ok: public int getReceiveBufferSize() throws SocketException; ok: public void setKeepAlive(boolean on) throws SocketException; ok: public boolean getKeepAlive() throws SocketException; ok: public void setTrafficClass(int tc) throws SocketException; ok: public int getTrafficClass() throws SocketException; ok: public void setReuseAddress(boolean on) throws SocketException; ok: public boolean getReuseAddress() throws SocketException; ok: public void close() throws IOException; ok: public void shutdownInput() throws IOException; ok: public void shutdownOutput() throws IOException; ok: public String toString(); ok: public boolean isConnected(); ok: public boolean isBound(); ok: public boolean isClosed(); ok: public boolean isInputShutdown(); ok: public boolean isOutputShutdown(); /
 


See superclass javadoc.
 
    public void bind(SocketAddress addressthrows IOException
    {
       if (isClosed())
          throw new SocketException("Socket is closed");
 
       if (isBound())
          throw new SocketException("Already bound");
 
       if (address != null && (!(address instanceof InetSocketAddress)))
          throw new IllegalArgumentException("Unsupported address type");
 
       InetSocketAddress inetAddress = (InetSocketAddressaddress;
 
       if (inetAddress != null && inetAddress.isUnresolved())
          throw new SocketException("Unresolved address");
 
        = MultiplexingManager.getaManagerByLocalAddress(inetAddress);
        = .getSocket();
        = new SocketId();
       if (.debug("bound virtual socket to port: " + .getPort());
        = true;
    }


See superclass javadoc.
 
    public void close() throws IOException
    {
       if ()
          return;
 
       .debug("closing: " + );
        = true;
 
       if ( && !)
          .disconnect();
 
       if ( != null)
          .close();
 
       if ( != null)
       {
          .flush();
          .close();
       }
 
       if ( != null)
          .releasePort();
 
       // This VirtualSocket might have been unregistered when connect() failed.
       if (.isSocketRegistered(this.))
       {
          MultiplexingManager.addToPendingActions(new PendingClose(this));
       }
 
       if (.debug("virtual socket closed on port: " + .getPort());
    }


   
See superclass javadoc.
 
    public void connect(SocketAddress socketAddressthrows IOException
    {
       connect(socketAddressnull);
    }


See superclass javadoc.
 
    public void connect(SocketAddress socketAddressint timeoutthrows IOException
    {
       connect(socketAddressnulltimeout);
    }


See superclass javadoc.
 
    public SocketChannel getChannel()
    {
       return null;
    }


See superclass javadoc.
 
    public InetAddress getInetAddress()
    {
       if ( == null)
          return null;
 
       return .getInetAddress();
    }


See superclass javadoc.
 
    public InputStream getInputStream() throws IOException
    {
       if (isClosed())
          throw new SocketException("Socket is closed");
 
       if ( == null || !)
          throw new SocketException("Socket is not connected");
 
       if (isInputShutdown())
          throw new SocketException("Socket input is shutdown");
 
       return ;
    }


See superclass javadoc.
 
    public boolean getKeepAlive() throws SocketException
    {
       if ( == null)
          return false;
 
       return .getKeepAlive();
    }


See superclass javadoc. Note. Socket.getLocalAddress() returns "wildcard" address for an unbound socket.
 
    public InetAddress getLocalAddress()
    {
       if ( == null)
       {
          if ( == null)
              = new Socket();
 
          return .getLocalAddress();
       }
 
       // The following is a workaround for a problem in NIO sockets, which sometimes
       // return "0.0.0.0" instead of "127.0.0.1".
       InetAddress address = .getLocalAddress();
       try
       {
          if ("0.0.0.0".equals(address.getHostAddress()))
             return InetAddress.getByName("localhost");
       }
       catch (UnknownHostException e)
       {
          return address;
       }
 
       return address;
    }


See superclass javadoc.
 
    public int getLocalPort()
    {
       if ( == null)
          return -1;
 
       return .getLocalPort();
    }


See superclass javadoc.
 
    {
       if ( == null)
          return null;
 
       InetSocketAddress socketAddress = null;
 
       // The following is a workaround for a problem in NIO sockets, which sometimes
       // return "0.0.0.0" instead of "127.0.0.1".
       if (address instanceof InetSocketAddress)
       {
          socketAddress = (InetSocketAddressaddress;
          if ("0.0.0.0".equals(socketAddress.getHostName()) ||
              socketAddress.getAddress() == null)
             return new InetSocketAddress("localhost"socketAddress.getPort());
       }
 
       return address;
    }


See superclass javadoc.
 
    public boolean getOOBInline() throws SocketException
    {
       return false;
    }


See superclass javadoc.
 
    public OutputStream getOutputStream() throws IOException
    {
       if (isClosed())
          throw new SocketException("Socket is closed");
 
       if ( == null || !)
          throw new SocketException("Socket is not connected");
 
       if (isOutputShutdown())
          throw new SocketException("Socket output is shutdown");
 
       // TODO: return distinct output streams? See PlainSocketImpl.
       //return new SocketOutputStream(this);
       return ;
    }


See superclass javadoc.
 
    public int getPort()
    {
       if ( == null)
          return 0;
 
       return .getPort();
    }


See superclass javadoc.
 
    public int getReceiveBufferSize() throws SocketException
    {
       if ( == null)
       {
          if ( == null)
              = new Socket();
 
          return .getReceiveBufferSize();
       }
 
       return .getReceiveBufferSize();
    }


See superclass javadoc.
 
    {
       if ( == null)
          return null;
 
       return .getRemoteSocketAddress();
    }


See superclass javadoc.
 
    public boolean getReuseAddress() throws SocketException
    {
       if ( == null)
          return false;
 
       return .getReuseAddress();
    }


See superclass javadoc.
 
    public int getSendBufferSize() throws SocketException
    {
       if ( == null)
       {
          if ( == null)
              = new Socket();
 
          return .getSendBufferSize();
       }
 
       return .getSendBufferSize();
    }


See superclass javadoc.
 
    public int getSoLinger() throws SocketException
    {
       if ( == null)
          return -1;
 
       return .getSoLinger();
    }


See superclass javadoc.
 
    public int getSoTimeout() throws SocketException
    {
       if (isClosed())
          throw new SocketException("Socket is closed");
 
       return ;
    }


See superclass javadoc.
 
    public boolean getTcpNoDelay() throws SocketException
    {
       if ( == null)
          return false;
 
       return .getTcpNoDelay();
    }


See superclass javadoc.
 
    public int getTrafficClass() throws SocketException
    {
       if ( == null)
          return 0;
 
       return .getTrafficClass();
    }


 
See superclass javadoc.
 
    public boolean isBound()
    {
       return ;
    }


See superclass javadoc.
 
    public boolean isClosed()
    {
       return ;
    }


See superclass javadoc.
 
    public boolean isConnected()
    {
       return ;
    }


See superclass javadoc.
 
    public boolean isInputShutdown()
    {
       return ;
    }


See superclass javadoc.
 
    public boolean isOutputShutdown()
    {
       return ;
    }


This method is not implemented.

See superclass javadoc.

 
    public void sendUrgentData(int datathrows IOException
    {
       .warn("sendUrgentData() called: ignored");
 
       if (isClosed())
          throw new IOException("Socket Closed");
    }


See superclass javadoc.
 
    public void setKeepAlive(boolean onthrows SocketException
    {
       if ( != null)
          .setKeepAlive(on);
    }


 
    public void setOOBInline(boolean onthrows SocketException
    {
       .warn("setOOBInLine() called: ignored");
 
       if (isClosed())
          throw new SocketException("Socket is closed");
    }


See superclass javadoc.
 
    public void setReceiveBufferSize(int sizethrows SocketException
    {
       if ( != null)
          .setReceiveBufferSize(size);
    }


See superclass javadoc.
 
    public void setReuseAddress(boolean onthrows SocketException
    {
       if ( != null)
          .setReuseAddress(on);
    }


See superclass javadoc.
 
    public void setSendBufferSize(int sizethrows SocketException
    {
       if ( != null)
          .setSendBufferSize(size);
    }


See superclass javadoc.
 
    public void setSoLinger(boolean onint lingerthrows SocketException
    {
       if ( != null)
          .setSoLinger(onlinger);
    }


See superclass javadoc.
 
    public void setSoTimeout(int timeoutthrows SocketException
    {
       if (isClosed())
          throw new SocketException("Socket is closed");
 
       if (timeout < 0)
          throw new IllegalArgumentException("timeout can't be negative");
 
       this. = timeout;
 
       if ( != null)
          .setTimeout(timeout);
    }


See superclass javadoc.
 
    public void setTcpNoDelay(boolean onthrows SocketException
    {
       if ( != null)
          .setTcpNoDelay(on);
    }


See superclass javadoc.
 
    public void setTrafficClass(int tcthrows SocketException
    {
       if ( != null)
          .setTrafficClass(tc);
    }


See superclass javadoc.
 
    public void shutdownInput() throws IOException
    {
       if (isClosed())
          throw new SocketException("Socket is closed");
 
       if (!isConnected())
          throw new SocketException("Socket is not connected");
 
       if (isInputShutdown())
          throw new SocketException("Socket input is already shutdown");
 
       .setEOF();
        = true;
       //         protocol.notifyInputShutdown(localSocketId);
    }


See superclass javadoc.
 
    public void shutdownOutput() throws IOException
    {
       if (isClosed())
          throw new SocketException("Socket is closed");
 
       if (!isConnected())
          throw new SocketException("Socket is not connected");
 
       if (isOutputShutdown())
          throw new SocketException("Socket output is already shutdown");
 
       .shutdown();
        = true;
    }


See superclass javadoc.
 
    public String toString()
    {
       StringBuffer answer = new StringBuffer().append("VirtualSocket[");
 
       if ( == null)
          answer.append("unbound");
       else
          answer.append(.toString());
 
       return answer.append("]").toString();
    }
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 ///                     The following methods are specific to VirtualSockets                   ///
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
    public void addDisconnectListener(DisconnectListener listener)
    {
       .add(listener);
    }


 
    public void connect(SocketAddress remoteAddressSocketAddress localAddressint timeoutthrows IOException
    {
       .debug("entering connect()");
       long start = System.currentTimeMillis();
       int timeLeft = 0;
 
       if (remoteAddress == null)
          throw new IllegalArgumentException("connect: The address can't be null");
 
       if (timeout < 0)
          throw new IllegalArgumentException("connect: timeout can't be negative");
 
       if (isClosed())
          throw new SocketException("Socket is closed");
 
       if (isConnected())
          throw new SocketException("already connected");
 
       if (!(remoteAddress instanceof InetSocketAddress))
          throw new IllegalArgumentException("Unsupported address type");
 
       InetSocketAddress remoteInetSocketAddress = (InetSocketAddressremoteAddress;
       SecurityManager security = System.getSecurityManager();
 
       if (security != null)
       {
          if (remoteInetSocketAddress.isUnresolved())
             security.checkConnect(remoteInetSocketAddress.getHostName(), remoteInetSocketAddress.getPort());
          else
             security.checkConnect(remoteInetSocketAddress.getAddress().getHostAddress(), remoteInetSocketAddress.getPort());
       }
 
       if (timeout > 0)
          if ((timeLeft = timeout - (int) (System.currentTimeMillis() - start)) <= 0)
             throw new SocketTimeoutException("connect timed out");
 
       if ( == null)
       {
          if (localAddress == null)
              = MultiplexingManager.getaShareableManager(remoteInetSocketAddresstimeLeft);
          else
          {
             InetSocketAddress localInetSocketAddress = (InetSocketAddresslocalAddress;
              = MultiplexingManager.getaShareableManagerByAddressPair(remoteInetSocketAddress,
                                                                             localInetSocketAddress,
                                                                             timeLeft,
                                                                             );
          }
       }
 
       try
       {
          if (timeout > 0)
             if ((timeLeft = timeout - (int) (System.currentTimeMillis() - start)) <= 0)
                throw new SocketTimeoutException("connect timed out");
 
          .connect(remoteInetSocketAddresstimeLeft);
           = .getSocket();
           = .getProtocol();
 
          if (!)
          {
              = new SocketId();
              = true;
          }
 
           = .registerSocket(this);
          .setTimeout(timeout);
 
          if (timeout > 0)
             if ((timeLeft = timeout - (int) (System.currentTimeMillis() - start)) <= 0)
                throw new SocketTimeoutException("connect timed out");
 
           = .connect(timeLeft);
           = new MultiplexingOutputStream(this);
       }
       catch (IOException e)
       {
          // Calling unRegisterSocket() will lead to this VirtualSocket being closed.
          try
          {
             .unRegisterSocket(this);
          }
          catch (IOException ignored)
          {
             // May not be registered yet.
          }
 
          if (e instanceof SocketTimeoutException)
             throw new SocketTimeoutException("connect timed out");
 
          throw e;
       }
       finally
       {
          if ( != null)
             .setTimeout(this.);
       }
 
        = true;
    }
 
 
    {
       return ;
    }
   public int getVirtualPort()
   {
      return .getPort();
   }
   public int getLocalVirtualPort()
   {
      return .getPort();
   }


Returns:
   {
      return ;
   }


Returns:
   public Socket getRealSocket()
   {
      return ;
   }


Returns:
   {
      return ;
   }


   
Returns true if and only if has not received notification of error state on actual connection.

Returns:
true if and only if has not received notification of error state on actual connection
   public boolean isFunctional()
   {
      return ;
   }

Parameters:
listener
   public void removeDisconnectListener(DisconnectListener listener)
   {
      if (!.remove(listener))
         .error("attempt to remove unregistered DisconnectListener: " + listener);
   }


Parameters:
configuration
   public void setConfiguration(Map configuration)
   {
      this..putAll(configuration);
   }
//////////////////////////////////////////////////////////////////////////////////////////////////
///                              Protected getters and setters                                '///
//////////////////////////////////////////////////////////////////////////////////////////////////

Returns:
Returns the actualSocket.
   protected Socket getActualSocket()
   {
      return ;
   }

Parameters:
actualSocket The actualSocket to set.
   protected void setActualSocket(Socket actualSocket)
   {
      this. = actualSocket;
   }
// in socket API section
///**
// * @return Returns the bound.
// */
//   public boolean isBound()
//   {
//      return bound;
//   }

Parameters:
bound The bound to set.
   protected void setBound(boolean bound)
   {
      this. = bound;
   }

Parameters:
closed The closed to set.
   protected void setClosed(boolean closed)
   {
      this. = closed;
   }

Parameters:
connected The connected to set.
   protected void setConnected(boolean connected)
   {
      this. = connected;
   }

Parameters:
inputShutdown The inputShutdown to set.
   protected void setInputShutdown(boolean inputShutdown)
   {
      this. = inputShutdown;
   }

Parameters:
inputStream The inputStream to set.
   protected void setInputStream(MultiplexingInputStream inputStream)
   {
      this. = inputStream;
   }

Parameters:
localSocketId The localSocketId to set.
   protected void setLocalSocketId(SocketId localSocketId)
   {
      this. = localSocketId;
   }

Returns:
   {
      return ;
   }

Parameters:
manager The manager to set.
   protected void setManager(MultiplexingManager manager)
   {
      this. = manager;
   }

Parameters:
outputShutdown The outputShutdown to set.
   protected void setOutputShutdown(boolean outputShutdown)
   {
      this. = outputShutdown;
   }

Parameters:
outputStream The outputStream to set.
   protected void setOutputStream(MultiplexingOutputStream outputStream)
   {
      this. = outputStream;
   }

Returns:
Returns the protocol.
   protected Protocol getProtocol()
   {
      return ;
   }

Parameters:
protocol The protocol to set.
   protected void setProtocol(Protocol protocol)
   {
      this. = protocol;
   }

Returns:
   protected boolean hasReceivedDisconnectMessage()
   {
      return ;
   }

Parameters:
receivedDisconnectMessage
   protected void setReceivedDisconnectMessage(boolean receivedDisconnectMessage)
   {
      this. = receivedDisconnectMessage;
   }

Parameters:
remoteSocketId The remoteSocketId to set.
   protected void setRemoteSocketId(SocketId remoteSocketId)
   {
      this. = remoteSocketId;
   }
//////////////////////////////////////////////////////////////////////////////////////////////////
///                                  Other protected methods                                  '///
//////////////////////////////////////////////////////////////////////////////////////////////////
   protected void doClose()
   {
      if (.debug("doClose()" + this..getPort());
      try
      {
//         if (connected && !receivedDisconnectMessage)
//            protocol.disconnect(remoteSocketId);
         // This VirtualSocket might have been unregistered when connect() failed.
            .unRegisterSocket(this);
         if (.debug("virtual socket closed on port: " + .getPort());
      }
      catch (Exception e)
      {
         .error("error closing socket: " + this);
         .error(e);
      }
   }



Throws:
IOException
   protected void handleRemoteOutputShutDown() throws IOException
   {
      // already closed ?
      try
      {
      }
      catch (NullPointerException ignored)
      {
      }
   }


   

Throws:
IOException
   protected void handleRemoteDisconnect() throws IOException
   {
      if (isClosed())
         return;
      if (.debug("remote virtual socket disconnecting: local port: " + getLocalVirtualPort());
       = true;
      // already closed ?
      if ( != null)
      // already closed ?
      if ( != null)
      {
         .flush();
      }
      MultiplexingManager.addToPendingActions(new PendingRemoteDisconnect(this));
      .debug("handleRemoteDisconnect(): done.");
      // TODO
      //     connected = false;
      //     inputShutdown = true;
      //     outputShutdown = true;
   }


   
Indicate error condition on actual connection.
   protected void notifyOfException()
   {
       = false;
   }
   protected class PendingRemoteDisconnect extends PendingAction
   {
      public PendingRemoteDisconnect(Object o)
      {
         super(o);
      }
      void doAction()
      {
         VirtualSocket vs = (VirtualSocket;
         Set disconnectListeners = vs.disconnectListeners;
         Iterator it = disconnectListeners.iterator();
         while (it.hasNext())
            ((DisconnectListenerit.next()).notifyDisconnected(vs);
      }
   }
   protected class PendingClose extends PendingAction
   {
      public PendingClose(Object o)
      {
         super(o);
      }
      public void doAction()
      {
         ((VirtualSocket)).doClose();
      }
   }