title: How to bind 2 UDP sockets to same port, one for receiving and other for sending
body: <p>I am working on a RTP streaming code on Android, where I need to <strong>receive</strong> RTP (<strong>UDP</strong>) packets on a port (say 5678) and <strong>send</strong> RTP packets from the <strong><em>same port</em></strong> (5678).
  Sender code and Receiver code are in separate locations, so a single socket cannot be used for both sending and receiving.</p>
  
  <p>For achieving this, I need to bind sender socket and receiver socket to same port using <strong>bind()</strong>. With just bind() on 2 sockets, I get error on 2nd bind(). (as expected)</p>
  
  <p>After doing search on other posts on StackOverflow, I found an option of using socket-option <strong>SO_REUSEADDR</strong> (<strong>SO_REUSEPORT</strong> not being available on Linux).</p>
  
  <p>With <strong>SO_REUSEADDR</strong>, I am able to bind() two sockets to the same port. The sender socket is able to sendto() from this port. But the receiver socket stops showing any incoming packets available for reading (<strong>select()</strong> + <strong>FD_ISSET()</strong> method of listening). If bind()ed to other port, receiver socket receives the incoming packets on the other port normally.</p>
  
  <p>So effectively, its only one socket is able to use the shared port, and other socket is just deprived of any packets.</p>
  
  <p>Any suggestions for improvements to SO_REUSEADDR approach or any other approach will be highly appreciated.</p>