Solved

CSocket and CArchive

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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 …
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

19 Experts available now in Live!

Get 1:1 Help Now