title: Try to send data from C++ to Python and reversed using socket C++, C++ sendto() and python recvfrom() working but not the reversed
body: <p>TLDR; I try to send data from C++ program to Python program and reversed, i managed to send data from C++ and received on python, but not send from python to C++</p>
  
  <p>Okay before going into code, i will explain what iam trying to do (Hope it will make understanding my code easier):
  I wanted to create a server which will listen and read an image from C++ Client and return another image</p>
  
  <p>(Server Side-Python)
  First i created a socket and bind it with localhost at port 5001</p>
  
  <p>(Client Side-C++)
  I created a socket, read an image (Here i use OpenCV) send image size first then send the image itself, and wait for server to respond</p>
  
  <p>(Server Side-Python)
  Read the size and read the image using the size it received </p>
  
  <p>-- At this point everything work as expected --</p>
  
  <p>(Server Side-Python)
  Server read and image and send it back</p>
  
  <p>(Client Side-C++)
  Client is freeze since it dont receive anything?</p>
  
  <p>It took me 4 hours with no result :( this is my code:</p>
  
  <p>Server Python</p>
  
  <pre><code>import socket
  import cv2
  import numpy
  import time
  
  
  UDP_IP = '127.0.0.1'
  UDP_PORT = 5001
  
  #Create socet here
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.bind((UDP_IP, UDP_PORT))
  
  #Get image size here
  length, addr = s.recvfrom(16)
  
  #read image data here
  stringData,addr = s.recvfrom(int(length))
  
  #Convert to opencv image format
  data = numpy.fromstring(stringData, dtype='uint8')
  decimg=cv2.imdecode(data,0)
  
  ############################################################################
  
  #Read an image
  sendBackImg = cv2.imread("cat.jpeg",0)
  
  #Encode file
  encode_param=[int(cv2.IMWRITE_JPEG_QUALITY),90]
  result, imgencode = cv2.imencode('.jpg', sendBackImg, encode_param)
  data = numpy.array(imgencode)
  stringData = data.tostring()
  
  #Send image size
  s.sendto(str(len(stringData)).zfill(16), (UDP_IP, UDP_PORT))
  # s.sendto(stringData, (UDP_IP, UDP_PORT))
  
  #Show image to check if it work correctly
  cv2.imshow('SERVER-SEND',sendBackImg)
  cv2.imshow('SERVER-SEND',decimg)
  
  cv2.waitKey(3000)
  
  s.close()
  
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>Client C++</p>
  
  <pre><code>#undef UNICODE
  
  #define WIN32_LEAN_AND_MEAN
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  #include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/socket.h&gt; 
  #include &lt;arpa/inet.h&gt; 
  #include &lt;opencv2/objdetect/objdetect.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  
  #define PORT 5001
  
  using namespace std;
  using namespace cv;
  
  int main(void)
  {
      int sock = 0, valread;
      struct sockaddr_in serv_addr;
  
      // read an image and show it so later and can compare with result on server side
      Mat frame = imread("dog.jpg",0);
      imshow("CLIENT",frame);
  
      // Encode image
      vector&lt;uchar&gt; buf;
      imencode(".jpg",frame,buf);
  
      const char *data = reinterpret_cast&lt;char*&gt;(buf.data());
  
      int strLength = buf.size();
  
      std::string strSizeTmp = std::to_string(strLength);
      strSizeTmp = string(16-strSizeTmp.length(),'0')+strSizeTmp ;
      char strSize[strSizeTmp.length()+1];
      strcpy(strSize, strSizeTmp.c_str());
  
      // Create socket
      memset(&amp;serv_addr, 0, sizeof(serv_addr)); 
      serv_addr.sin_family = AF_INET; 
      serv_addr.sin_port = htons(PORT); 
      serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  
      if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) &lt; 0) 
      { 
          printf("\n Socket creation error \n"); 
          return -1; 
      } 
  
      //Send image size and image data
      sendto(sock, (const char *)strSize, 16, 
          MSG_CONFIRM, (const struct sockaddr *) &amp;serv_addr,  
              sizeof(serv_addr));
      sendto(sock, (const char *)data, strLength, 
          MSG_CONFIRM, (const struct sockaddr *) &amp;serv_addr,  
              sizeof(serv_addr));
  
      //////////////////////////////////////////////////////////
  
      //Wait for respond
      char bufferTmp[16] ; 
      cout &lt;&lt; "Wait" &lt;&lt; endl;
      recvfrom(sock, (char *)bufferTmp, 16,  
                  MSG_WAITALL, (struct sockaddr *) NULL, 
                  NULL);
      // The program just nerver reach here
      cout &lt;&lt; bufferTmp &lt;&lt; endl;
  
  
      close(sock);
  
      waitKey(3000);
  }
  </code></pre>
  
  <p>There is one thing i noticed that c++ recvfrom doesnt required ip and port, how does it know which port to listen to?</p>