Solved

CSocket and CArchive

Posted on 1998-07-14
1
416 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 90
Excel Use VBA to get user's Mac Address for their computer 5 109
maxBlock challenge 30 111
NotAlone Challenge 20 79
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now