void CServerSocket::OnReceive(int nErrorCode)
{
AfxBeginThread(MessegeProcessing,this);
CSocket::OnReceive(nErrorCode);
}
UINT CServerSocket::MessegeProcessing(LPVOID pParam)
{
CSocket* m_consocket=(CSocket*)pParam;
CSingleLock m_singlock(&m_mutex);
HWND hWndMain=m_pDlg->GetSafeHwnd();
if (!m_singlock.IsLocked())
{
m_singlock.Lock();
TCHAR buff[4096];
int nRead;
nRead = m_consocket->Receive(buff, 4096);
CString m_str;
switch (nRead)
{
case 0:
m_consocket->Close();
break;
case SOCKET_ERROR:
if (GetLastError() != WSAEWOULDBLOCK)
{
AfxMessageBox ("Ошибка в принятии сообщения");
m_consocket->Close();
}
break;
default:
buff[nRead] = 0;
CString szTemp(buff);
int m_comand;
CString m_Data;
m_comand=StrToInt(szTemp.Left(5));
m_Data=szTemp.Right(szTemp.GetLength()-6);
switch(m_comand)
{
case ID_SHOW:
::SendMessage(hWndMain, WMU_SHOWPEPORTDATA,
reinterpret_cast<WPARAM>(&m_Data), reinterpret_cast<LPARAM>(m_consocket));
break;
case ID_REVIEW:
::SendMessage(hWndMain, WMU_REVIEW,
reinterpret_cast<WPARAM>(&m_Data), reinterpret_cast<LPARAM>(m_consocket));
break;
case ID_EXECUTEQUERY:
::SendMessage(hWndMain, WMU_EXECUTEQUERY,
reinterpret_cast<WPARAM>(&m_Data), reinterpret_cast<LPARAM>(m_consocket));
break;
default:
break;
}
m_singlock.Unlock();
}
}
return 0;
}