C# to unix image file transfer
<p>I have a TCPListener in C# and the client in Unix C.  I use TcpClient.Client.SendFile for transmitting a file to client socket in Unix and it works fine for plain txt file.  It fails to produce the full file on the unix end, when I send JPEG files.  Any Idea?</p>

<pre><code>C# code part
============
static void Main(string[] args)
        {
            TcpListener serverSocket = new TcpListener(10001);           
            TcpClient clientSocket = default(TcpClient);
            serverSocket.Start();
            Console.WriteLine(" &gt;&gt; Server Started");
            clientSocket = serverSocket.AcceptTcpClient();
            Console.WriteLine(" &gt;&gt; Accept connection from client");            

            while ((true))
            {
                try
                {                    
                    NetworkStream networkStream = clientSocket.GetStream();
                    byte[] bytesFrom = new byte[10025]; 
                    networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                    string dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom).TrimEnd('\0');
                    Console.WriteLine(" &gt;&gt; Data from client - " + dataFromClient +" Length "+ dataFromClient.Length);                   

                    string a1 = "C:\\MRTD\\PICTURE\\abc.jpg";
                   clientSocket.Client.SendFile(a1);  
                                   }
                catch (Exception ex)
                {
                   Console.WriteLine(ex.ToString());
                   Console.ReadLine();
                }
            }

        }

    }
}

Unix C code to read the file
============================
char *tcp_recv( int id_type )
{
    register int nbytes;
    static char readbuf[MAXLINE];
    static char tempbuf[980000];
    int ngot = 0, bulk_data=0, p_read_val;
    char  * x, * y, * z, *j, *k, *x1, *bar;
    char bulk_buf[180000], tempstr1[180000] , fstr[40],  termtor[40];

    int    fd_ready;
    fd_set read_fds;           /* Read file descriptors */
    int    fd_port = gfd_sock;
    struct timeval timeout;


    timeout.tv_sec = 3600;
    timeout.tv_usec = 0;

    while (TRUE)
    {

        FD_ZERO( &amp;read_fds );

        FD_SET( fd_port, &amp;read_fds );

        strcpy(fstr,"FAIL");

        if((fd_ready = select(fd_port+1,&amp;read_fds,NULL,NULL,&amp;timeout))&lt; 0)
        {
          if( errno == EINTR ) { continue; }
            logmsg("ERROR select() returned errno %d", errno );
            logmsg("Select error waiting for packet." );
            return fstr;
        }
        else if( fd_ready == 0 )
        {
            logmsg("Timeout waiting for packet.");
            strcpy(fstr,"TIMEOUT");
            return fstr;
        }


        memset( readbuf, 0x00, sizeof( readbuf ));
        memset( br_kde, 0x00, sizeof( br_kde ));

        if((nbytes = read( fd_port, readbuf, sizeof(readbuf)-1 )) &lt; 0 )
        {
            logmsg( "tcp_recv: nbytes %d, errno %d, %s", nbytes, errno, strerror( errno ) );

            if (errno == EINTR || errno == EAGAIN )
            {
                errno = 0;
                continue;     /* assume SIGCLD */
            }
            else
            {
                /*
                 * connection failer.
                 */
              logcon( "Desko connection failed. Pier link is DOWN!" );
              logmsg( "Desko connection failed. Pier link is DOWN!" );
              close_files();
              exit (1);
              break;
            }   /* end else if */
        }
        else
        {

              logmsg("tcp_recv: readbuf is %s, bytes %d", readbuf, nbytes);         

              strcat(tempbuf, readbuf);
              logmsg("tempbuf is %s", tempbuf );&lt;== full file listing is missing in case of JPEG

         }
          return tempbuf;
}
}
</code></pre>