i want to learn about CSocket, where i can find the details and sample
program of this MFC class.
Thanks
You can find details and a sample program for CSocket in the Visual C++ help. Search for "CSocket" and "Chatter".
--
----------------------------------------
Rajesh Parikh
Microsoft Certified Solution Developer
nospam_...@usa.net
remove nospam_ from the email address
----------------------------------------
VisualC wrote in message <6v4m1h$64...@news1.cityu.edu.hk>...
////////////////////////////////////////////////////////////////////////////
/
// Written by Kevers Gabriel 30/12/96
// Class CClientSocket
// CliSock.h : header file
//
// CliSock.cpp : implementation file
//
#include "stdafx.h"
#include "winsock.h"
#include "CliSock.h"
#include "MagiComCtl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////////////
/
// CClientSocket
IMPLEMENT_DYNAMIC(CClientSocket, CSocket)
CClientSocket::CClientSocket(CMagiComCtrl *pWnd )
{
m_pParrent=pWnd;
}
CClientSocket::~CClientSocket()
{
Send("Je Quitte",strlen("Je Quitte"));
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CClientSocket, CSocket)
//{{AFX_MSG_MAP(CClientSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
////////////////////////////////////////////////////////////////////////////
/
// CClientSocket member functions
void CClientSocket::Error(int error)
{
CString str;
switch(error)
{
case WSANOTINITIALISED:
str="A successful AfxSocketInit must occur before using this API";
break;
case WSAENETDOWN:
str="The Windows Sockets implementation detected that the network
subsystem failed";
break;
case WSAENOTCONN:
str="The socket is not connected";
break;
case WSAEINPROGRESS:
str="A blocking Windows Sockets operation is in progress";
break;
case WSAENOTSOCK:
str="The descriptor is not a socket";
break;
case WSAEOPNOTSUPP:
str="MSG_OOB was specified, but the socket is not of type SOCK_STREAM";
break;
case WSAESHUTDOWN:
str="The socket has been shut down; it is not possible to call Receive on
a socket after ShutDown has been invoked with nHow set to 0 or 2";
break;
case WSAEWOULDBLOCK:
str="The socket is marked as nonblocking and the Receive operation would
block";
break;
case WSAEMSGSIZE:
str="The datagram was too large to fit into the specified buffer and was
truncated";
break;
case WSAEINVAL:
str="The socket has not been bound with Bind";
break;
case WSAECONNABORTED:
str="The virtual circuit was aborted due to timeout or other failure";
break;
case WSAECONNRESET:
str="The virtual circuit was reset by the remote side";
break;
case WSANO_RECOVERY:
str="Nonrecoverable errors: FORMERR, REFUSED, NOTIMP.";
break;
case WSANO_DATA:
str="Valid name, no data record of requested type.";
break;
case WSAEINTR:
str="The (blocking) call was canceled using WSACancelBlockingCall.";
break;
case WSAEADDRINUSE:
str="The specified address is already in use.";
break;
case WSAEADDRNOTAVAIL:
str="The specified address is not available from the local machine.";
break;
case WSAEAFNOSUPPORT:
str="Addresses in the specified family cannot be used with this socket.";
break;
case WSAECONNREFUSED:
str="The attempt to connect was forcefully rejected.";
break;
case WSAEDESTADDRREQ:
str="A destination address is required.";
break;
case WSAEFAULT:
str="The lpSockAddrLen argument is incorrect.";
break;
case WSAEISCONN:
str="The socket is already connected.";
break;
case WSAEMFILE:
str="No more file descriptors are available.";
break;
case WSAENETUNREACH:
str="The network cannot be reached from this host at this time.";
break;
case WSAENOBUFS:
str="No buffer space is available. The socket cannot be connected.";
break;
case WSAETIMEDOUT:
str="The attempt to connect timed out without establishing a
connection.";
break;
case WSAEACCES:
str="The requested address is a broadcast address, but the appropriate
flag was not set.";
break;
case WSAENETRESET:
str="The connection must be reset because the Windows Sockets
implementation dropped it.";
break;
}
if(!str.IsEmpty())AfxMessageBox(str);
}
BOOL CClientSocket::ConnectToServer(CString cli,CString adr,int m_iChannel)
{
if (!this->Create())
{
Error(GetLastError());
AfxMessageBox("Echec lord de la creation de la socket");
return FALSE;
}
while (!this->Connect(adr, m_iChannel))
{
if (AfxMessageBox("reesayer la connection ?",MB_YESNO) == IDNO)
{
Error(GetLastError());
return FALSE;
}
}
Send((LPCTSTR)cli,cli.GetLength()); // pas util, on l'utilise pour un
connection TCP/MUX cli=services name
m_Client=cli;
return TRUE;
}
void CClientSocket::OnConnect(int nErrorCode)
{
i f(m_pParrent!=NULL) { // connection OK };
CSocket::OnConnect(nErrorCode);
}
void CClientSocket::OnClose(int nErrorCode)
{
i f(m_pParrent!=NULL) { // connection close };
CSocket::OnClose(nErrorCode);
}
void CClientSocket::OnReceive(int nErrorCode)
{
i f(m_pParrent!=NULL) { // you recive data };
CAsyncSocket::OnReceive(nErrorCode);
}
etc ....
nice work
Gabriel Kevers
Rajesh Parikh (MCSD) a écrit dans le message ...