Bonjour voici mon pb j'esaye d'accepter une connexion entrante en utilisant la class CAsyncSocket . Des que j'ai une connexion entrante mon programme me mets un message d'erreur. Je ne vois pas du tout d'ou peu venir l'erreur voici mon prog.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
void TCPSocket::OnAccept(int nErrorCode) 
{
 
	Accept( *((CServerDlg*)m_pDlg)->SocketTCP1 );
	CAsyncSocket::OnAccept(nErrorCode);
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
void CServerDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	//CREATE 2 SOCKETS dans le protocole choisit
	UpdateData(TRUE);
 
	LPCTSTR addrip="172.24.247.84";
	long lEvent = FD_READ| FD_WRITE| FD_OOB| FD_ACCEPT| FD_CONNECT| FD_CLOSE;
 
	//MODE TCP
	if(mode==1)
	{
			//Nouveau objet TCP1
			if ((SocketTCP1 = new TCPSocket(this)) == NULL) 
			{
				AfxMessageBox ("Failed to allocate listen socket TCP1! Close and restart app.");
				return;
			}
			//Nouveau objet TCP2
			if ((SocketTCP2 = new TCPSocket(this)) == NULL) 
			{
				AfxMessageBox ("Failed to allocate listen socket TCP2! Close and restart app.");
				return;
			}
 
			//CREATION SOCKET TCP1
			if ( SocketTCP1 ->Create(m_port,SOCK_STREAM,lEvent,addrip) != TRUE )
			{
				wsprintf(m_szError, "Failed to create listen socket TCP1: %d! Close and restart app.", SocketTCP1->GetLastError());
				AfxMessageBox (m_szError);
				return;
			}
			else
			{
				m_affiche = m_affiche +"CREATION SOCKET TCP1 OK \n ";
			}
 
			//CREATION SOCKET TCP2
			if ( SocketTCP2 ->Create(m_port+1,SOCK_STREAM,lEvent,addrip) != TRUE )
			{
				wsprintf(m_szError, "Failed to create listen socket TCP2: %d! Close and restart app.", SocketTCP1->GetLastError());
				AfxMessageBox (m_szError);
				return;
			}
			else
			{
				m_affiche = m_affiche + "CREATION SOCKET TCP2 OK \n ";
			}
 
			//Listen TCP1
			if (SocketTCP1 ->Listen() != TRUE)
			{
				wsprintf(m_szError, "Failed to listen TCP1: %d! Close and restart app.", SocketTCP1->GetLastError());
				AfxMessageBox (m_szError);
				return;
			}
			else
			{
				m_affiche = m_affiche+"LISTEN SOCKET TCP1 OK \n ";
			}
			//Listen TCP2
			if (SocketTCP2 ->Listen() != TRUE)
			{
				wsprintf(m_szError, "Failed to listen TCP2: %d! Close and restart app.", SocketTCP2->GetLastError());
				AfxMessageBox (m_szError);
				return;
			}
			else
			{
				m_affiche = m_affiche +"LISTEN SOCKET TCP2 OK \n ";
			}
 
 
		UpdateData(FALSE);
	}
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
// serverDlg.h : header file
//
 
#if !defined(AFX_SERVERDLG_H__11E095EE_2C80_46B8_BD87_0181C87E786B__INCLUDED_)
#define AFX_SERVERDLG_H__11E095EE_2C80_46B8_BD87_0181C87E786B__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
 
#include "TCPSocket.h"
#include "UDPSOcket.h"
 
/////////////////////////////////////////////////////////////////////////////
// CServerDlg dialog
 
class CServerDlg : public CDialog
{
// Construction
public:
	CServerDlg(CWnd* pParent = NULL);	// standard constructor
 
// Dialog Data
	//{{AFX_DATA(CServerDlg)
	enum { IDD = IDD_SERVER_DIALOG };
 
	TCPSocket* SocketTCP1;
	TCPSocket* SocketTCP2;
 
	UDPSocket* SocketUDP1;
	UDPSocket* SocketUDP2;
 
	int mode;
 
	UINT	m_port;
	CString	m_affiche;
 
	//}}AFX_DATA
	TCHAR	m_szError[255];
 
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CServerDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL
 
// Implementation
protected:
	HICON m_hIcon;
 
	// Generated message map functions
	//{{AFX_MSG(CServerDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnRadio1();
	afx_msg void OnRadio2();
	afx_msg void OnButton1();
	afx_msg void OnButton2();
	afx_msg void OnButton3();
	afx_msg void OnButton4();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};
 
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 
#endif // !defined(AFX_SERVERDLG_H__11E095EE_2C80_46B8_BD87_0181C87E786B__INCLUDED_)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
#if !defined(AFX_TCPSOCKET_H__DDEB249F_C8F1_42C4_A6A7_576D53C8CA05__INCLUDED_)
#define AFX_TCPSOCKET_H__DDEB249F_C8F1_42C4_A6A7_576D53C8CA05__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// TCPSocket.h : header file
//
 
#include <afxsock.h>
 
/////////////////////////////////////////////////////////////////////////////
// TCPSocket command target
 
class TCPSocket : public CAsyncSocket
{
// Attributes
public:	
	CDialog*	m_pDlg;
 
// Operations
public:
	TCPSocket(CDialog* pDlg);	
	virtual ~TCPSocket();
 
// Overrides
public:
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(TCPSocket)
	public:
	virtual void OnAccept(int nErrorCode);
	virtual void OnClose(int nErrorCode);
	virtual void OnConnect(int nErrorCode);
	virtual void OnOutOfBandData(int nErrorCode);
	virtual void OnReceive(int nErrorCode);
	virtual void OnSend(int nErrorCode);
	virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0);
	virtual int Send(const void* lpBuf, int nBufLen, int nFlags = 0);
	virtual BOOL Create( UINT nSocketPort = 0, int nSocketType = SOCK_STREAM, long lEvent = FD_READ| FD_WRITE| FD_OOB| FD_ACCEPT| FD_CONNECT| FD_CLOSE, LPCTSTR lpszSocketAddress = NULL );
	virtual BOOL Bind( UINT nSocketPort, LPCTSTR lpszSocketAddress = NULL );
	virtual BOOL Listen( int nConnectionBacklog =5 );
	virtual void Close();
	virtual BOOL Socket( int nSocketType = SOCK_STREAM, long lEvent = FD_READ| FD_WRITE| FD_OOB| FD_ACCEPT| FD_CONNECT| FD_CLOSE, int nProtocolType = 0, int nAddressFormat = PF_INET );
	virtual int GetLastError();
	virtual BOOL GetPeerName( SOCKADDR* lpSockAddr, int* lpSockAddrLen );
	virtual BOOL GetSockName( SOCKADDR* lpSockAddr, int* lpSockAddrLen );
 
 
	//}}AFX_VIRTUAL
 
	// Generated message map functions
	//{{AFX_MSG(TCPSocket)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG
 
// Implementation
protected:
};
 
/////////////////////////////////////////////////////////////////////////////
 
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 
#endif // !defined(AFX_TCPSOCKET_H__DDEB249F_C8F1_42C4_A6A7_576D53C8CA05__INCLUDED_)
Sur l'exemple que l'on ma donnée sa marcher si vous avez une id merci d'avance