Solved

CSocket and CArchive

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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