我的代码中的(一对多)服务器要同时和多台客户机通讯,由于接受函数在主线程中影响了操作界面的刷新,所以想把接收函数变成一个线程,请高手们指点!
void CCommunictionDlg::ProcessAccept(CAcceptSocket*m_pSocket)//增加连接队列函数
{
CServiceSocket *pSocket = new CServiceSocket(this);
if (m_pSocket->Accept(*pSocket))
{
s_cs_client.Lock();
.....
pSocket->GetPeerName(Ip, Port);
.....
conn.pSock = pSocket;
m_connectionList.AddTail(conn);//用户链表
s_cs_client.Unlock();
}
}
我怎样把“CServiceSocket *pSocket = new CServiceSocket(this);”初始化了pSocket传给全局的工作线程函数UINT _ReceiveMsgThread(LPVOID lparam) //TCP发送信息线程函数
{
......
nReceived = pSocket.Receive(&protocol_rev,sizeof(Protocol));
...
}
void CCommunictionDlg::ProcessAccept(CAcceptSocket*m_pSocket)//增加连接队列函数
{
CServiceSocket *pSocket = new CServiceSocket(this);
if (m_pSocket->Accept(*pSocket))
{
s_cs_client.Lock();
.....
pSocket->GetPeerName(Ip, Port);
.....
conn.pSock = pSocket;
m_connectionList.AddTail(conn);//用户链表
s_cs_client.Unlock();
}
}
我怎样把“CServiceSocket *pSocket = new CServiceSocket(this);”初始化了pSocket传给全局的工作线程函数UINT _ReceiveMsgThread(LPVOID lparam) //TCP发送信息线程函数
{
......
nReceived = pSocket.Receive(&protocol_rev,sizeof(Protocol));
...
}
让后通过((你的App*)(AfxGetApp()))->psocket.........
通过((你的App*)(AfxGetApp()))->psocket来实现
有Detach()和Attach()的例子呀!
用在全局工作线程,Attach()怎样用呢?和AfxBeginThread()有关联吗
有Detach()和Attach()的例子呀!
用在全局工作线程,Attach()怎样用呢?和AfxBeginThread()有关联吗?另外,给分呀!