小弟写的一个C/S程序,还要实现以下几个功能,但本人一点思路都没有,望各位大侠指点:
1.服务器端可连接多个客户端,每连接一个客户端,该客户端的ip地址都会被插入一个checklistbox中显示,在该客户端退出的时候,如何让在checklistbox中显示的ip地址自动消失。
2.只对checklistbox中选中的ip地址发信息。
相关代码如下:
void CListeningSocket::OnAccept(int nErrorCode) 
{
  CClientSocket* pSocket=new CClientSocket(m_pMyServerDlg);
  
  if(m_pMyServerDlg->m_pListeningSocket->Accept(*pSocket))
  {
      m_pMyServerDlg->m_pConnectionList.AddTail(pSocket);
  
  m_pMyServerDlg->m_pClientSocket=pSocket;
  }
  else
delete pSocket;  CString PeerAddress;
  unsigned int PeerPort;
  CString str1,str2;
  
  pSocket->GetPeerName(PeerAddress,PeerPort);
  str1.Format("%s : %u - Connected",PeerAddress, PeerPort);
  m_pMyServerDlg->m_list.InsertString(0,str1);  str2.Format("%s:%u", PeerAddress, PeerPort);
  m_pMyServerDlg->m_CheckListBox.InsertString(0,str2);
}void CMyServerDlg::SendMsg(CClientSocket* pClientSocket,char* pMsg)
{
int count = m_pConnectionList.GetCount();

for(int idx=0; idx<count; idx++)
{
POSITION pos=m_pConnectionList.FindIndex(idx);

CClientSocket* pClientSocket=(CClientSocket*)m_pConnectionList.GetAt(pos);

pClientSocket->Send(pMsg, strlen(pMsg));
}
}