?
Solved

communication

Posted on 2003-02-24
5
Medium Priority
?
199 Views
Last Modified: 2013-11-20
how to write a program for communication using CAsyncSocket.
please send me a sample Client & Server programs.
0
Comment
Question by:shanuka
[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
5 Comments
 

Author Comment

by:shanuka
ID: 8007925
how to use CAsyncSocket
0
 

Expert Comment

by:kusamson
ID: 8012601
Server side:
you need to derive two classes from CAsyncSocket , 1 for listening, the other for the actual communication.

class CServSck : public CAsyncSocket{} // for listening
class CCommunicateSck : public CAsyncSocket{} // for communicating

// you need to create your listen socket in you main
// program
CServSck listenSck;
listenSck.Create(8888); // listening port
listenSck.Listen();

// in your listen socket
void CServSck::Accept(int nErrorCode)
{ // the listen socket will create a new communicate
  // socket and accept the client using the communicate
  // socket

  CCommunicateSck *pComSck = new CCommunicateSck;
  Accept(*pComSck);
  CAsyncSocket::OnAccept(nErrorCode);
}

// modify the various functions such as OnConnect, OnClose, Send, etc in the communicate socket class

Client Side:
you need to derive one class from CAsyncSocket

class CClientSck : public CAsyncSocket{}
// in your main program create a client socket and connect to the server

CClientSck clientSck;
clientSck.Create();
clientSck.Connect("127.0.0.1", 8888);// specify the IP and port

// client socket will receive OnConnect when the socket is connected so you want to modify CClientSck::OnConnect to add your action when the socket is connected
// modify various functions in CClientSck as needed

0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11812132
PAQed - no points refunded (of 50)

modulo
Community Support Moderator
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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