Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

communication

how to write a program for communication using CAsyncSocket.
please send me a sample Client & Server programs.
0
shanuka
Asked:
shanuka
1 Solution
 
shanukaAuthor Commented:
how to use CAsyncSocket
0
 
kusamsonCommented:
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
 
moduloCommented:
PAQed - no points refunded (of 50)

modulo
Community Support Moderator
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now