bonjour,
j'ai deux appli:une sur pc et l'autre pocket pc.
je communique entre les deux par WiFi.
j'arrive a envoyer un message de mon appli pocket pc vers le pc mais pas le contraire.
j'ai l'impression que mon appli de pocket pc n'appelle jamais les méthodes de notification OnAccept(),OnConnect() et OnReceive().
C'est pourquoi ca ne marche pas.
Mais je vois pas comment faire pour qu'elles soient appelées.
voici mon code lors du démarrage du serveur coté pocket pc:
le code de demande de connexion au serveur coté pc:
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 void CAppliTestDlg::OnRunServeur() { //Creation Socket d'ecoute niveau serveur if( oMonSocketEcoute.Create(4000) == FALSE) { CString sTxt; sTxt.Format(_T("Erreur de Create: %d,\r\n"), GetLastError()); CString sTxt1; GetDlgItemText(IDC_EDIT_INFO_RECUE, sTxt); sTxt1 += sTxt; SetDlgItemText(IDC_EDIT_INFO_RECUE, sTxt1 + "\r\n"); oMonSocketEcoute.Close(); return ; } if( oMonSocketEcoute.Listen() == FALSE) { CString sTxt; sTxt.Format(_T("Erreur de Listen: %d,\r\n"), GetLastError()); CString sTxt1; GetDlgItemText(IDC_EDIT_INFO_RECUE, sTxt); sTxt1 += sTxt; SetDlgItemText(IDC_EDIT_INFO_RECUE, sTxt1 + "\r\n"); oMonSocketEcoute.Close(); return ; } }
mon code lors de l'appui sur le bouton "envoi message" coté pc vers pocket pc:
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 void CClient_ServeurDlg::OnConnectSrv() { // TODO: Add your control notification handler code here if( oMonSocketClient.Create() == FALSE) { CString sTxt1; GetDlgItemText(IDC_MSG_ENV, sTxt1); CString sTxt2; sTxt2.Format("Erreur de Create: %d,\r\n", GetLastError()); SetDlgItemText(IDC_MSG_ENV, sTxt1 + sTxt2 + "\r\n"); oMonSocketClient.Close(); return ; } GetDlgItem(IDC_IP_SRV)->EnableWindow(FALSE); GetDlgItem(IDC_PORT)->EnableWindow(FALSE); GetDlgItem(IDC_ENVOI_MSG)->EnableWindow(TRUE); GetDlgItem(IDC_MSG)->EnableWindow(TRUE); int iPort = GetDlgItemInt(IDC_PORT); CString sIP; GetDlgItemText(IDC_IP_SRV,sIP); int j; char cIP[15] = ""; for (j=0;j<sIP.GetLength();j++) { cIP[j] = sIP.GetAt(j); } if( oMonSocketClient.Connect(cIP, iPort) == FALSE) { CString sTxt; sTxt.Format("Erreur de Connect: %d,\r\n", GetLastError()); CString sTxt1; GetDlgItemText(IDC_MSG_ENV, sTxt1); SetDlgItemText(IDC_MSG_ENV, sTxt1 + sTxt + "\r\n"); return ; } }
et enfin mon code lors de la réception coté pocket pc:
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 void CClient_ServeurDlg::OnEnvoiMsg() { char* msg = NULL; int msgLength = 0; CString sTxt = ""; GetDlgItemText(IDC_MSG,sTxt); if(sTxt.IsEmpty() == TRUE) { return; } msg = sTxt.GetBuffer(0); msgLength = sTxt.GetLength(); ASSERT( msg != NULL); ASSERT( msgLength >0); int i = oMonSocketClient.Send( msg, msgLength); CString sTxt2; sTxt2.Format(" Nb de car env: %d,\r\n", i); CString sTxt1; GetDlgItemText(IDC_MSG_ENV, sTxt1); SetDlgItemText(IDC_MSG_ENV, sTxt1 + sTxt2 + "\r\n"); }
Et je dois avouer que je comprends pas car avec le même principe ma communication client serveur fonctionne de pc a pc.
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 void CMonAsyncSocketClientConnecte::OnReceive(int nErrorCode) { CString sTxt2; if( nErrorCode != 0) // Code d'erreur retourné par OnReceive { sTxt2.Format(_T("Erreur de OnReceive: %d,\r\n"), GetLastError()); } else // OnReceive OK { sTxt2 = "OnReceive OK"; } CAsyncSocket::OnReceive(nErrorCode); //char MsgRecu[2096]; // définition du buffer LPTSTR MsgRecu = (LPTSTR) (char*) malloc(2096); int iTaille = Receive(MsgRecu, 2096); // Réception qui retourne le nombre de d'octets reçus MsgRecu[iTaille] = '\0'; CString sTxt; sTxt.Format(_T("%s"), MsgRecu); m_pParent->GetDlgItemText(IDC_EDIT_INFO_RECUE, sTxt2); sTxt2 += sTxt; m_pParent->SetDlgItemText(IDC_EDIT_INFO_RECUE, sTxt2 + "\r\n"); }
Alors aidez moi siouplé les gens![]()
Partager