Problem with reading from Socket using CArchive::Read()
-
Hi all, I have client application and server application (FTP server / client). On client side, due to certain reasons, I use CArchive to write / read data to / from socket. On the server side I use CSockets to send / receive data. It worked fine for me, but now I implemented encrypted communication (Twofish cipher) and want to exchange the data safely. When I send encrypted data from client to server (ie. CArchive::Write()), it is ok. But when I use CSocket::Send() to send encrypted data from server to client, on client side the call of CArchive::Read() doesn't return and after a while it throws CFileException (OS Error it says). My method for sending encrypted data from server to client is the following: [CODE] DWORD dwToAllocate = CTwofishCipher::getPaddedSize(strlen(s) + 3) + TC_BLOCK_HEADER_SIZE; BYTE* encryptedData = new BYTE[dwToAllocate]; memset(encryptedData, 0x00, dwToAllocate); encryptAnswer(stringToSend, encryptedData); pControlSocket->sendEncryptedString(encryptedData, dwToAllocate); void CMyControlSocket::sendEncryptedString(BYTE* encryptedData, INT dataLen) { CSocket::Send(encryptedData, dataLen, 0); } [/CODE] And the code of client for receive encrypted data is here: [CODE] BYTE* receivedData = NULL; UINT nBytesRead = 0; TRY { receivedData = (BYTE *) m_retmsg.GetBuffer(32000); nBytesRead = m_pCtrlRxarch->Read((TCHAR*) receivedData, 32000); m_retmsg.ReleaseBuffer(); } CATCH(CFileException ,e) { ErrorCode = e->m_lOsError; return FALSE; } END_CATCH [/CODE] The interesting is that when I check received data on client side (after it throws the exception after a while), the bytes received exactly match the bytes which had been sent. Anyway, the function CArchive::Read() has apparently some difficulty receiving the buffer. Thanks for any suggestion!