Socket
public Socket(String host,
              int port,
              InetAddress localAddr,
              int localPort)
       throws IOException
Creates a socket and connects it to the specified remote host on the specified remote port. The Socket will also bind() to the local address and port supplied. 
If there is a security manager, its checkConnect method is called with the host address and port as its arguments. This could result in a SecurityException. Parameters:
host - the name of the remote host
port - the remote port
localAddr - the local address the socket is bound to
localPort - the local port the socket is bound to
Throws:
IOException - if an I/O error occurs when creating the socket.
SecurityException - if a security manager exists and its checkConnect method doesn't allow the operation.
Since:
JDK1.1 
See Also:
SecurityManager.checkConnect(java.lang.String, int)

解决方案 »

  1.   

    why do you have to bind local port?
    i think u can just use Socket(String host, int port), if u just use the socket as client socket.
      

  2.   

    isClosed() means u have dropped down from remote host, but ur socket still binds on localhost at local port. so isBound() should be true. but i don't clear why isConnected() returns true.
      

  3.   

    我的问题是当我的socket 作完一次通信,然后断开,然后再连接时,报错:
    java.net.BindException: Address already in use: JVM_Bind
      

  4.   

    please use Socket(String host, int port) to construct a new client socket.when you did all your things, close it an let the socket be null.
      

  5.   

    看来只好使用Socket(String host, int port)了。