Home > Software engineering >  About MFC realize two computers communication sending and receiving information
About MFC realize two computers communication sending and receiving information

Time:11-24

Should be connected through the, the relevant code is as follows, can send, but couldn't receive,
Void MySocket: : OnReceive (int nErrorCode)
{
//TODO: add in this dedicated code and/or call the base class
TCHAR TBuffer [4096]={0};

M_nLength=Receive (m_szBuffer, sizeof (m_szBuffer), 0).

CMainFrame * pFrame=(CMainFrame *) AfxGetApp () - & gt; M_pMainWnd;
PDlg DNetWorkChess *=(DNetWorkChess *) pFrame - & gt; The GetActiveWindow ();

M_szBuffer MultiByteToWideChar (0, 0, 1, TBuffer, 4069);

AfxMessageBox (TBuffer, MB_OK, 0);

PDlg - & gt; M_LRMSG. InsertString (0, TBuffer);

Memset (m_szBuffer, 0, sizeof (m_szBuffer));

CAsyncSocket: : OnReceive (nErrorCode);
}
Red annotation to the pop-up dialog,

Void MySocket: : OnSend (int nErrorCode)
{
//TODO: add in this dedicated code and/or call the base class
TCHAR TBuffer [4096]={0};

Send (m_szBuffer, m_nLength, 0);
M_nLength=0;

M_szBuffer MultiByteToWideChar (0, 0, 1, TBuffer, 4069);

AfxMessageBox (TBuffer, MB_OK, 0);

Memset (m_szBuffer, 0, sizeof (m_szBuffer));

AsyncSelect (FD_READ);

CAsyncSocket: : OnSend (nErrorCode);
}
Sending can be the pop-up dialog,


Send button code
Void DNetWorkChess: : OnBnClickedBsend ()
{
//TODO: add the control notification handler code
TCHAR TCHBuffer [4096].

//if (m_itype==1)
//{
If (m_clientSocket. M_bConnected)
{
M_EMessage. GetWindowTextW (TCHBuffer, 4069);
WideCharToMultiByte (TCHBuffer CP_ACP, 0, 1, m_clientSocket. M_szBuffer, 4069, NULL, NULL);
M_clientSocket. AsyncSelect (FD_WRITE);
M_EMessage. SetWindowText (_T (" "));
}
//}
/* else if (m_itype==0)
{
If (m_servSocket. M_pSocket - & gt; M_bConnected)
{
M_EMessage. GetWindowTextW (TCHBuffer, 4069);
WideCharToMultiByte (TCHBuffer CP_ACP, 0, 1, m_servSocket. M_pSocket - & gt; M_szBuffer, 4069, NULL, NULL);
M_servSocket. M_pSocket - & gt; AsyncSelect (FD_WRITE);
M_EMessage. SetWindowText (_T (" "));
}
} */
}
  • Related