IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

Pb accept connection


Sujet :

MFC

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2006
    Messages : 134
    Par défaut Pb accept connection
    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

  2. #2
    Membre émérite
    Avatar de Spout
    Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    904
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Février 2007
    Messages : 904
    Par défaut
    Pourquoi passer la CDialog en paramètre lors de la création de tes sockets?

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2006
    Messages : 134
    Par défaut
    Je passe CDialog en parametre pour pouvoir ensuite faire dans mes redefinition de fonction OnReceive ceci

    ((CServerDlg*)m_pDlg)->m_affiche += "Reception Ok";
    ((CServerDlg*)m_pDlg)->UpdateData(FALSE);

    Sa me permet d'afficher ensuite, je me base sur l'exemple mfc qui utilise CAsyncSocket.

    Comme erreur j'ai exactement :
    Debug Assertion failed
    Chemin ou il ya mon prog
    File:sockcore.cpp
    Line: 178

    J'ai verifier que mon pointeur ne soit pas null, il n'est pas null.
    Ensuite j'ai verifier pas à pas au debuggeur et je ne trouve rien
    la valeur de l'adresse m_pDlg est bien egale a mon ancien this lors de la creation de mon nouveau objet.
    Je cherche encore si vous avez une id pour trouver dou vient mon erreur. Merci d'avance

  4. #4
    Membre émérite
    Avatar de Spout
    Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    904
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Février 2007
    Messages : 904
    Par défaut
    Citation Envoyé par doommick31
    Ensuite j'ai verifié pas à pas au debuggeur et je ne trouve rien
    Il doit bien te dire à quelle ligne ça plante?

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    134
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mars 2006
    Messages : 134
    Par défaut
    C'est bon jai trouver dou venait le beug, je resume si vous regarder l'exemple du mfc c'est un menage a 3 socket et moi je n'utiliser que 2 socket et sa planter. Pour plus d'inof je vous redirige sur le code de l'exmple mfc sur asyncsocket voila merci.

  6. #6
    Membre émérite
    Avatar de Spout
    Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    904
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Février 2007
    Messages : 904
    Par défaut

Discussions similaires

  1. Réponses: 4
    Dernier message: 11/08/2009, 13h41
  2. Réseau - Problème d'acceptation connection entrante
    Par superolive dans le forum VB.NET
    Réponses: 1
    Dernier message: 08/06/2008, 14h18
  3. Réponses: 0
    Dernier message: 08/03/2008, 20h13
  4. Réponses: 2
    Dernier message: 07/11/2006, 09h15
  5. connect sans accept
    Par gui31 dans le forum Réseau
    Réponses: 3
    Dernier message: 14/09/2005, 10h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo