PREVIOUS
Now we will talk about the other MFC GUI portion which I have created and used threaded model.
When in GUI the start button is clicked by providing port number on PORT text box this server start by creating a thread independent from GUI. You can start the server by ENTER also.
Here is some code snap for help --
void CServerDlg::OnBnClickedButton1()Here we create a windows thread for back end action.
{
// TODO: Add your control notification handler code here
cTh = AfxBeginThread(
StaticThreadFunc,
this);
//cTh->m_bAutoDelete = FALSE;
m_Thread_handle = cTh->m_hThread;
}
UINT __cdecl CServerDlg::StaticThreadFunc(LPVOID pParam)On ThredFunc() we take the input from text box and pass this value on to ServerMnager class and start the server.
{
CServerDlg *pYourClass = reinterpret_cast<CServerDlg*>(pParam);
UINT retCode = pYourClass->ThreadFunc();
return retCode;
}
UINT CServerDlg::ThreadFunc()
{
// Do your thing, this thread now has access to all the classes member variables
CString txtname;
GetDlgItemText(IDC_EDIT1, txtname);
int iPort = _wtoi( txtname.GetString() );
if(iPort == 0)
{
return -1;
}
m_pServer = new ServerManager(this);
m_pServer->StartListening(iPort);
return 0;
}
No comments:
Post a Comment