Click here to Skip to main content
15,909,939 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Which lib is corresponding to Dskquota.h? Pin
Anonymous18-Sep-02 4:46
Anonymous18-Sep-02 4:46 
GeneralRe: Which lib is corresponding to Dskquota.h? Pin
Le centriste18-Sep-02 6:22
Le centriste18-Sep-02 6:22 
GeneralRe: Which lib is corresponding to Dskquota.h? Pin
Anonymous18-Sep-02 8:04
Anonymous18-Sep-02 8:04 
GeneralMaking Right align Rich Edit box ! Pin
Hadi Rezaee18-Sep-02 4:07
Hadi Rezaee18-Sep-02 4:07 
GeneralProblem with SQL FETCH Pin
Cheickna18-Sep-02 4:04
Cheickna18-Sep-02 4:04 
GeneralRe: Problem with SQL FETCH Pin
TyMatthews18-Sep-02 5:10
TyMatthews18-Sep-02 5:10 
GeneralPassing a file through a Socket Pin
RobJones18-Sep-02 3:44
RobJones18-Sep-02 3:44 
GeneralRe: Passing a file through a Socket Pin
TyMatthews18-Sep-02 5:57
TyMatthews18-Sep-02 5:57 
To send across the file name, you could prepend the file's data with the file's name in a header struct, which appears to be what you were starting to do. Your receive code would have to be more intelligent in this case... instead of just dumping whatever it receives over the socket into a file, you'd have to look for the header first and then continue on.

It's important that your receive code only pulls in the header initially, and that it doesn't spill over into the file data. That's what

  nRead = pSocket->Receive( byBuffer + nPos, sizeof( FileHeader ) - nPos );
  nPos += nRead;    
</code>


is doing in the following pseudo code. It will only read at a maximum sizeof( FileHeader ) bytes. You can't assume that you'll get all of those bytes in one pass, however, which is why you still have to put it in a do..while.

typedef struct
{
   char szFileName[_MAX_PATH];
} FILE_HEADER, *LPFILE_HEADER;

send_code()
{
   ... Get the file name
   #define BUFFER_SIZE  4096
   long nRead = 0;
   BYTE byBuffer[BUFFER_SIZE];   // Only build this once
   FILE_HEADER FileHeader;

   strcpy( FileHeader.szFileName, myFile.GetFileName() );

   // Send the header struct
   cSocket->Send( dynamic_cast< LPVOID >( &FileHeader ), sizeof( FileHeader ));

   do
   {
      nRead = myFile.Read( byBuffer, BUFFER_SIZE );
      cSocket->Send( byBuffer, nRead );
   } while( nRead > 0 );

   ... clean up
}

receive_code()
{
    long nRead = 0;
    long nPos = 0;
    BYTE byBuffer[BUFFER_SIZE];
    FILE_HEADER FileHeader;

    // Get the header struct
    do
    {
         nRead = pSocket->Receive( byBuffer + nPos, sizeof( FileHeader ) - nPos );
         nPos += nRead;
    } while( (nPos < sizeof( FileHeader )) && (nRead > 0) );

    // Make sure we got at least the FileHeader
    if( nPos != sizeof( FileHeader ) )
    {
        // Abort... data is incomplete
        return;
    }

    ... create file with FileHeader.szFileName

    do
    {
         nRead = pSocket->Receive( byBuffer, BUFFER_SIZE );
         destFile.write( byBuffer, nRead );
    } while( nRead > 0 );
}

</code>


Ty


"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein


GeneralRe: Passing a file through a Socket Pin
Bilal18-Sep-02 6:32
Bilal18-Sep-02 6:32 
GeneralRe: Passing a file through a Socket Pin
RobJones18-Sep-02 6:57
RobJones18-Sep-02 6:57 
GeneralRe: Passing a file through a Socket Pin
RobJones18-Sep-02 11:06
RobJones18-Sep-02 11:06 
GeneralRe: Passing a file through a Socket Pin
Bilal18-Sep-02 20:42
Bilal18-Sep-02 20:42 
GeneralUTF-8 to Unicode or ANSI. Pin
Halls18-Sep-02 3:25
Halls18-Sep-02 3:25 
GeneralRe: UTF-8 to Unicode or ANSI. Pin
Stephane Rodriguez.18-Sep-02 3:37
Stephane Rodriguez.18-Sep-02 3:37 
GeneralAfxBeginThread Pin
vampiras^18-Sep-02 3:15
sussvampiras^18-Sep-02 3:15 
GeneralRe: AfxBeginThread Pin
Chris Meech18-Sep-02 3:55
Chris Meech18-Sep-02 3:55 
QuestionHow to pass address of a method to a function Pin
Raphael Kindt18-Sep-02 3:06
Raphael Kindt18-Sep-02 3:06 
AnswerRe: How to pass address of a method to a function Pin
Stephane Rodriguez.18-Sep-02 3:40
Stephane Rodriguez.18-Sep-02 3:40 
AnswerRe: How to pass address of a method to a function Pin
Joaquín M López Muñoz18-Sep-02 4:08
Joaquín M López Muñoz18-Sep-02 4:08 
AnswerRe: How to pass address of a method to a function Pin
Axter18-Sep-02 5:16
professionalAxter18-Sep-02 5:16 
Generalstd::string Pin
Furrukh18-Sep-02 2:15
Furrukh18-Sep-02 2:15 
GeneralRe: std::string Pin
jhwurmbach18-Sep-02 2:31
jhwurmbach18-Sep-02 2:31 
GeneralRe: std::string Pin
Joaquín M López Muñoz18-Sep-02 4:05
Joaquín M López Muñoz18-Sep-02 4:05 
GeneralRe: std::string Pin
Axter18-Sep-02 5:31
professionalAxter18-Sep-02 5:31 
GeneralProcessing Speed Pin
:_Rocket_:18-Sep-02 1:45
:_Rocket_:18-Sep-02 1:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.