title: How wait a ServerSocket connection on client Socket
body: <p>I am wondering about, how I can wait a ServerSocket connection on Socket client side.</p>
  
  <p>When I execute the server (send) first, it waits the client connection with the method ServerSocket.accept. The problem is that the client (receive) cannot be executed without the server has been executed first. I would like add a condition to allow the client to wait the connection from the server. Is it possible?</p>
  
  <p>SEND (server)</p>
  
  <pre><code>ServerSocket servsock = new ServerSocket(1234);
  Socket sock = servsock.accept();
  </code></pre>
  
  <p>RECEIVE (client)</p>
  
  <pre><code>Socket sock = new Socket(from, 1234);
  </code></pre>
  
  <p>ERROR (client)</p>
  
  <pre><code>java.net.ConnectException: Connection refused
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
      at java.net.Socket.connect(Socket.java:529)
      at java.net.Socket.connect(Socket.java:478)
      at java.net.Socket.&lt;init&gt;(Socket.java:375)
      at java.net.Socket.&lt;init&gt;(Socket.java:189)
  </code></pre>
  
  <p>Thank you.</p>