title: Sending data over socket from C server to qt Client
body: <p>I am in bit of a problematic situation here:</p>
  
  <p>I have a simple C server (can't use Qt TcpServer, limitations of the embedded board) which sends <strong>double</strong>  data (generated by GPIO ports) over tcpsocket using <strong>send()</strong>. If I have a simple C client (in my Linux PC) then I am able to get the real time data as is generated with the help of <strong>recv()</strong>. Here is my server code:</p>
  
  <pre><code>int main (void){
      int s,b,l,fd,sa,bytes,on=1;
      char buf[BUF_SIZE],fname[255];
      struct sockaddr_in channel;
  
      long long sum=0;
      double average=0;
      int i,j;
      int srno=0;
  
      s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
      if(s&lt;0)
      {
          printf("socket creation failure");
          exit(0);
      }
      setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&amp;on,sizeof(on));
      memset(&amp;channel,0,sizeof(channel));
      channel.sin_family=AF_INET;
      channel.sin_addr.s_addr=htonl(INADDR_ANY);
      channel.sin_port=htons(SERVER_PORT);
      b=bind(s, (struct sockaddr *)&amp;channel,sizeof(channel));
      if(b&lt;0)
      {
          printf("bind error");
          exit(0);
      }
      listen(s,5);
      while(1)
      {
          printf("waiting for request\n");
          sa=accept(s,0,0);
          if(sa&lt;0)
          {
              printf("accept failure");
          }
          for (i=1; i&lt;=56; i++)               //for 10 sec &gt;&gt; 56
          {   
              for(j=1;j&lt;=20;j++)
              {
  
              //more than 100 lines of code here
              }               
              average=(sum/20)*1.22;
              send(sa, &amp;average, sizeof(average), 0);
  
              //int tmp = htonl((uint32_t)average); //tried this also
              //send(sa, &amp;tmp, sizeof(tmp), 0);
  
              // int n = write(sa, &amp;average, sizeof(average)) //and tried this also
              // if(n&lt;0){
              // printf("error");}
  
              printf("%lld \n", average);
              srno++; 
              sum=0;
              average=0;      
          }
      }
      remove_gpio();  
      close(s);
      return 0;
  }
  </code></pre>
  
  <p>But I am unable to get to display the data in Qt Client, it is driving me crazy. In my <em>QtextEdit</em> I get non-ASCII characters, whatever I try. inside my <strong>startRead()</strong> I did</p>
  
  <blockquote>
    <p>...</p>
    
    <p>QByteArray Data = socket->readAll();</p>
    
    <p>ui->textEdit->append(QString(Data));</p>
    
    <p>...</p>
  </blockquote>
  
  <p>I also tried  using other methods <strong>bytesavailable() canreadLine()</strong>, and also went through  other links but was unsuccessful.</p>
  
  <p>Non-ASCII crazy characters is what I get everytime. Sorry not able to give a pic due to low rep.
  I need help regarding sending double data through socket and be able to work with the data or atleast display them in a QTextEdit/QPlainTextEdit. </p>
  
  <p>Thanks.</p>