Solved

CSocket and CArchive

Posted on 1998-07-14
1
425 Views
Last Modified: 2013-11-20
Do I have to use a CArchive to either read or send something from a CSocket class?  Any sample that I've seen so far is using the CArchive to read things from the CSocket.  Would you please give me a code sample how to read something from my socket class?  Here is the sequence:
I call Receive() from my OnReceive function.

Thank you
Allen
0
Comment
Question by:akhaligh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
VEngineer earned 20 total points
ID: 1319144
If you do not want to use CArchive, then use class CAsyncSocket.  CAsyncSocket is a lower level abstraction and gives you more control of the socket.

class MySocket : public CAsyncSocket
// inherit CAsyncSocket to let you use all its functions as well as adding your own overrides for notifications

// your other functions to process data...

void MySocket::OnReceive() {
   int bytesReceived = 0;
   char dataBuffer[256];
   
   // Receive() is inherited from CAsyncSocket
   bytesReceived = Receive(dataBuffer, sizeof(dataBuffer));

   // call your other member functions to process the data in dataBuffer
}

That's all there is to it.  The data received from the server is stored in dataBuffer.  The length of dataBuffer has to be worked out when you design the packets that will be sent from the server side.

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question