title: Setting source port on udp socket
body: <p>We've developed a Java application that sends several UDP datagrams to the very same destination IP address. Obviously the destination port is always the same one, but we can't seem to be able to set the source port to remain the same on each datagram. <br>
  If the data package we send is bigger than MTU the package is properly splitted over the same source port, but once we send a new data package the source port changes, generating a new firewall session (which network admin has warned us to be very bad due to the amount of sessions the application is generating).</p>
  
  <p>Right now we're sending the packages with the following statement:</p>
  
  <p>We've tried several approaches and the result is always the same, we can't seem to be able to set the source port to a fixed value.</p>
  
  <p>Edit- pasting actual code:</p>
  
  <pre><code>private boolean sendImage(byte[] imageData, InetAddress address,
  int port) throws UnknownHostException, SocketException {
  
      boolean ret = false;
  
  
      DatagramSocket socket = null;
  
      try {
          socket = new DatagramSocket();
          DatagramPacket dp = new DatagramPacket(imageData, imageData.length, address, PUERTO_UDP);
          socket.send(dp);
          ret = true;
      } catch (IOException e) {
          Main.lanzarExcepcion(e);
          ret = false;
      } finally {
          if (socket != null) {
               socket.close();
          }
      }
  
      return ret;
  }
  </code></pre>
  
  <p>Thanks for your time!</p>