title: How to easily solve the 10040 message too long error on Wsock2
body: <p>I'm sending from a .Net application 1404 float values which make up for 5616 bytes through an udp socket. I get no exceptions off this operation.</p>
  
  <p>However, the program receiving those data, is a C++ application, and when receiving such amount of data I get a 10040 message too long error.</p>
  
  <p>Apparently 1480bytes is the longest size possible for messages in Wsock2.</p>
  
  <p>What would be the easiest, cleanest way to fix this?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: Posting some code:</p>
  
  <p>This is my socket J_Receive class:</p>
  
  <pre><code>#include "J_Receive.h"
  
  
  #include &lt;stdio.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/types.h&gt;
  #if defined (WIN32) &amp;&amp; !defined(__CYGWIN__)
  #include &lt;winsock.h&gt;
  #else
  #include &lt;unistd.h&gt;
  #include &lt;sys/uio.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;sys/time.h&gt;
  #endif
  #include &lt;string.h&gt;
  
  #include &lt;iostream&gt;
  
  using namespace sockets;
  
  J_Recibir::J_Recibir( void )
  {
      _port = 0;
      _initialized = false;
      _buffer = 0L;
  }
  
  J_Recibir::~J_Recibir( void )
  {
  #if defined (WIN32) &amp;&amp; !defined(__CYGWIN__)
      closesocket( _so);
  #else
      close( _so );
  #endif
  }
  
  bool J_Recibir::init( void )
  {
  #if defined(WIN32) &amp;&amp; !defined(__CYGWIN__)
      WORD version = MAKEWORD(1,1);
      WSADATA wsaData;
      // First, we start up Winsock
      WSAStartup(version, &amp;wsaData);
  #endif
  
      if( _port == 0 )
      {
      fprintf( stderr, "Receiver::init() - port not defined\n" );
      return false;
      }
  
      if( (_so = socket( AF_INET, SOCK_DGRAM, 0 )) &lt; 0 )
      {
          perror( "Socket" );
      return false;
      }
  
  
  
      /*int buffsize  = 50000;
      setsockopt( _so, SOL_SOCKET, SO_RCVBUF, (const char*)&amp;buffsize, sizeof(buffsize));*/
  
  #if defined (WIN32) &amp;&amp; !defined(__CYGWIN__)
  //    const BOOL on = TRUE;
  //    setsockopt( _so, SOL_SOCKET, SO_REUSEADDR, (const char*) &amp;on, sizeof(int));
  #else
      int on = 1;
      setsockopt( _so, SOL_SOCKET, SO_REUSEADDR, &amp;on, sizeof(on));
  #endif
  
  
  
  
  //    struct sockaddr_in saddr;
      saddr.sin_family = AF_INET;
      saddr.sin_port   = htons( _port );
  #if defined (WIN32) &amp;&amp; !defined(__CYGWIN__)
      saddr.sin_addr.s_addr =  htonl(INADDR_ANY);
  #else
      saddr.sin_addr.s_addr =  0;
  #endif
  
      if( bind( _so, (struct sockaddr *)&amp;saddr, sizeof( saddr )) &lt; 0 )
      {
          perror( "bind" );
          return false;
      }
  
      u_long iMode = 1;       // 1 para No bloqueante, 0 para bloqueante
      ioctlsocket(_so, FIONBIO, &amp;iMode);
  
      _initialized = true;
      return _initialized;
  }
  
  
  void J_Recibir::setPort( const short port )
  {
      _port = port;
  }
  
  void J_Recibir::setBuffer( void *buffer, const unsigned int size )
  {
      _buffer = buffer;
      _buffer_size = size;
  }
  
  int J_Recibir::sync( void )
  {
      if(!_initialized) init();
  
      if( _buffer == 0L )
      {
          fprintf( stderr, "Receiver::sync() - No buffer\n" );
          return -1;
      }
  
  #if defined(__linux) || defined(__FreeBSD__) || defined( __APPLE__ )
      socklen_t 
  #else
      int
  #endif
          size = sizeof( struct sockaddr_in );
  
      fd_set fdset;
      FD_ZERO( &amp;fdset );
      FD_SET( _so, &amp;fdset );
  
      struct timeval tv;
      tv.tv_sec = 0;
      tv.tv_usec = 0;
  
  #if defined (WIN32) &amp;&amp; !defined(__CYGWIN__)
  //    saddr.sin_port   = htons( _port );
      recvfrom( _so, (char *)_buffer, _buffer_size, 0, (sockaddr*)&amp;saddr, &amp;size );
  
  
  //    recvfrom(sock_Receive, szMessage, 256, 0, (sockaddr*)&amp;addr_Cli, &amp;clilen)
      int err = WSAGetLastError ();
      if (err!=0){
          fprintf( stderr, "Receiver::sync() - error %d\n",err );
          perror("Error: ");
      }
  
      while( select( _so+1, &amp;fdset, 0L, 0L, &amp;tv ) )
      {
          if( FD_ISSET( _so, &amp;fdset ) )
          {
              recvfrom( _so, (char *)_buffer, _buffer_size, 0, (sockaddr*)&amp;saddr, &amp;size );
          }
      }
  #else
      recvfrom( _so, (caddr_t)_buffer, _buffer_size, 0, 0, &amp;size );
      while( select( _so+1, &amp;fdset, 0L, 0L, &amp;tv ) )
      {
          if( FD_ISSET( _so, &amp;fdset ) )
          {
              recvfrom( _so, (caddr_t)_buffer, _buffer_size, 0, 0, &amp;size );
          }
      }
  #endif
  
      if (err!=0) return -1;
      else        return 0;
  }
  </code></pre>
  
  <p>And this is how I call the receive function:</p>
  
  <pre><code>     sockets::J_Receiver receiverGUI = new sockets::J_Recibir();
       receiverGUI-&gt;setPort(4020);
       nDatosGUI = 1404;
       float* datosGUI = new datosGUI[nDatosGUI ];
       receiverGUI-&gt;setBuffer((void *)datosGUI, sizeof(float)*nDatosGUI);
  </code></pre>