title: How do I send 10,000 ~ 20,000 bytes data over TCP?
body: <p>Can I send about 10,000 ~ 20,000 bytes data over TCP? I am transferring an image (60 by 60) from Android client to linux server. On android it seems ok. On server side, if I try to send the picture data back to client, then it doesn't work. On client side, if I parse then I got some weird number that I shouldn't get. </p>
  
  <p>Is there any technical problem of transferring a big data over TCP? How do I fix this?
  Thanks in advance..</p>
  
  <pre><code>char* PictureResponsePacket::toByte(){
  
      /*
       * HEADER
       *
       * Magic number (4)
       * Data length  (4)
       * Packet Id    (2)
       * Packet type  (2)
       * Device Id    (48)
       *
       */
  
      /*
       * BODY
       *
       * Nickname  (48)
       * deviceId  (4)
       * m_pictureSize
       */
  
      int offset = 0;
  
      int headerLength = sizeof(int) + sizeof(int) + sizeof(short) + sizeof(short) + 48;
      int bodyLength = 48 + 4 + m_pictureSize;
      int dataLength = headerLength + bodyLength;
      m_dataLength = dataLength;
  
      log("PictureResponsePacket::toByte(), data length %d \n", m_dataLength);
  
      char *sendBuffer = new char[dataLength];
      memset(sendBuffer, 0x00, dataLength);
  
      char *ptr = sendBuffer;
  
      /*
       * -------------
       * HEADER
       * -------------
       */
      /*
       * Magic number
       */
      memcpy(ptr + offset, m_magicNumberBuffer, sizeof(int));
      offset += sizeof(int);
  
      /*
       * Data length
       */
  
  
      memcpy(ptr + offset, &amp;m_dataLength, sizeof(int));
      offset += sizeof(int);
  
      /*
       * Packet id
       */
      memcpy(ptr + offset, &amp;m_packetId, sizeof(short));
      offset += sizeof(short);
  
      /*
       * Packet type
       */
      memcpy(ptr + offset, &amp;m_packetType, sizeof(short));
      offset += sizeof(short);
  
      /*
       *Device Id
       */
  
      memcpy(ptr + offset, m_deviceId.c_str(), m_deviceId.size());
      offset += 48;
  
      /*
       * -------------
       * BODY
       * -------------
       */
      memcpy(ptr + offset, m_senderDeviceId.c_str(), m_senderDeviceId.size());
      offset += 48;
  
      memcpy(ptr + offset, &amp;m_pictureSize, sizeof(int));
      offset += sizeof(int);
  
      memcpy(ptr + offset, m_pictureData, m_pictureSize);
      offset += m_pictureSize;
  
  
      return sendBuffer;
  
  
  }
  </code></pre>
  
  <p>I am getting char* this way and sending it like this</p>
  
  <pre><code>                char * sBuffer = reponsePacket-&gt;toByte();
                  int remainLength = reponsePacket-&gt;getDataLength();
                  int currentSentLength = 0;
                  SocketClient *client = work-&gt;getClient();
  
                  while(remainLength &gt; 0){
  
                      if(remainLength &gt;= MAX_LENGTH)
                          currentSentLength = send(client-&gt;getFd(), sBuffer, MAX_LENGTH, MSG_NOSIGNAL);
                      else
                          currentSentLength = send(client-&gt;getFd(), sBuffer, remainLength, MSG_NOSIGNAL);
  
                      if(currentSentLength == -1){
                          log("WorkHandler::workLoop, connection has been lost \n");
                          break;
                      }
  
                      sBuffer += currentSentLength;
                      remainLength -= currentSentLength;
  </code></pre>