Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with reading from Socket using CArchive::Read()

Problem with reading from Socket using CArchive::Read()

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadminregex
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    s_k
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups