Solved

CSocket and CArchive

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 85
iSeries DB2 Query 2 97
Smart Camera scanning and reading information 3 113
Updating statistics with error notification email in SQL server 4 109
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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