局域网一对一聊天程序,
原来写两个程序,成对使用,即一个是Server端,一个是Client端。现在将两个程序合为一个,代码以原来Server端的为蓝本,能连接成功,但接受不了消息,会是什么地方出错了呢?

解决方案 »

  1.   

    我看是风水不对你这么描述你的问题,谁能解决阿?
    ============================================================================
    DocWizard C++ 程序文档生成工具 http://www.betajin.com/alphasun/index.htm
      

  2.   

    注意,在一个程序中,Server Client的SOCKET要是不同的,如果用的是MFC的话,要实例化两个Socket对象
      

  3.   

    应该看看基本的网络通讯程序,就知道了。
    建立SOCKET列表。
      

  4.   

    具体一些,Server端CServer m_server; 
    CServer m_recv;
    void CLx2Dlg::OnSend() 
    {
    UpdateData(TRUE); //更新数据,使m_msg得到当前框中文本
    m_recv.Send(m_msg, 255); //发送数据
    m_ctrl.SetSel(0, -1); //全选发送框文字
    m_ctrl.ReplaceSel("", TRUE);//将发送框置空
    }
    void CServer::OnReceive(int nErrorCode) 
    {
    // TODO: Add your specialized code here and/or call the base class
    CSocket::OnReceive(nErrorCode);
    ((CLx2Dlg*)(AfxGetApp()->m_pMainWnd))->ShowMsg();
    }
    void CLx2Dlg::ShowMsg()
    {
    char buf[255];
    m_recv.Receive(buf, 255); //接收消息到buf里面,长度255字节。
    CString msg;
    msg.Format("%s", buf); //用AfxMessageBox函数显示接收到的字符窜。
    AfxMessageBox(msg); /这里注意CString类的用法
    }Client端CClient m_client;
    void CLx1Dlg::OnSend() 
    {
       UpdateData(TRUE); //更新数据,使m_msg得到当前框中文本
       m_client.Send(m_msg, 255); //发送数据,长度255字节
    }void CClient::OnReceive(int nErrorCode) 
    {
    // TODO: Add your specialized code here and/or call the base class
    ((CLx1Dlg*)(AfxGetApp()->m_pMainWnd))->ShowMsg();
    CSocket::OnReceive(nErrorCode);
    }
    void CLx1Dlg::ShowMsg()
    {
    char buf[255];
    m_client.Receive(buf, 255); //接收消息到buf里面,长度255字节。
    CString msg;
    msg.Format("%s", buf);
    AfxMessageBox(msg); //用AfxMessageBox函数显示接收到的字符窜。
    }
    合为一个程序时,两个OnSend()如何整合呢,两个ShowMsg()如何整合呢?
      

  5.   

    一对一聊天需要分什么server和client嘛?
    对等就可以了把