title: java.io.IOException: Can't assign requested address with DatagramSockets
body: <p>I have a spreadsheet application in Java, and one of the features it provides (which I developed) is sheet sharing. Basically, anyone can be a client or a server because the app has both server and client code. The user who is the server creates the share, specifies the IP, and then the share is created and active (best case scenario) with the server listening for clients on its IP and selected port.</p>
  
  <p>For auto-discovery, I am using DatagramSockets via UDP broadcasts, while the 'real communication' is TCP-based (after the client is already connected).</p>
  
  <p>I already have this code to send a list of active shares from server to client (it sends a <code>List</code> of <code>InetSocketAddress</code>). </p>
  
  <p>The server:</p>
  
  <pre><code>public class BroadcastList implements Runnable {
          private final int BROADCAST_PORT = 8888;
  
          public BroadcastList() {
          }
  
          @Override
          public void run() {
              try {
                  ActiveShareList asl = new ActiveShareList();
                  List&lt;InetSocketAddress&gt; shareList = asl.getActiveShareList();
                  DatagramSocket broadcast = new DatagramSocket(BROADCAST_PORT);
                  ByteArrayOutputStream out = new ByteArrayOutputStream();
                  ObjectOutputStream outputStream = new ObjectOutputStream(out);
                  outputStream.writeObject(shareList);
                  outputStream.close();
  
                  byte[] listData = out.toByteArray();
                  byte[] message = new byte[10];
  
                  DatagramPacket listPacket = new DatagramPacket(listData, listData.length);
                  DatagramPacket messagePacket = new DatagramPacket(message, message.length);
  
                  broadcast.receive(messagePacket);
                  broadcast.send(listPacket);
  
              } catch (IOException ex) {
                  ex.printStackTrace();
              }
          }
      }
  </code></pre>
  
  <p>The client:</p>
  
  <pre><code>public void getShareList() {
          DatagramSocket socket;
          try {
              InetSocketAddress address = new InetSocketAddress("255.255.255.255", 8888);
              socket = new DatagramSocket();
  
              byte[] buffer = new byte[10];
              List&lt;InetSocketAddress&gt; shareList = new ArrayList&lt;InetSocketAddress&gt;();
              byte[] listData = new byte[65535];
              DatagramPacket messagePacket = new DatagramPacket(buffer, buffer.length, address.getAddress(), address.getPort());
              DatagramPacket listPacket = new DatagramPacket(listData, listData.length);
  
              socket.send(messagePacket);
              socket.receive(listPacket);
              ObjectInputStream inputStream = new ObjectInputStream(new ByteArrayInputStream(listData));
  
              try {
                  shareList = (List&lt;InetSocketAddress&gt;) inputStream.readObject();
              } catch (ClassNotFoundException ex) {
                  Logger.getLogger(JoinShareAction.class.getName()).log(Level.SEVERE, null, ex);
              }
  
  }
  </code></pre>
  
  <p>The problem lies with the client, it's giving me a <code>java.io.IOException: Can't assign requested address</code> error on this line: <code>socket.send(messagePacket);</code>.</p>
  
  <p>Anyone know what's the issue?</p>