服务段端发送函数:void CBITDlg::SendMsg()
{
if(!m_SocketList.IsEmpty())
{
UpdateData(true);
POSITION pos;
CClientSocket* pSocket=(CClientSocket*)m_SocketList.GetHead();
int count;
for(pos=m_SocketList.GetHeadPosition();pos!=NULL;)
{
pSocket=(CClientSocket*)m_SocketList.GetNext(pos);
pSocket->Send(sen,sen.GetLength()); }
count=sen.GetLength();
sen.Empty();
UpdateData(false);
}
else
MessageBox(_T("未建立有Socket连接,无法传递消息!"),_T("服务器程序"));
}客户端接收函数:
void CBITRevDlg::ReceiveMsg(CChatSocket *pSocket)
{wchar_t buff[1000];
int count;
count=pSocket->Receive(buff,1000);
buff[count]=0;b.Format(_T("%s"),buff);
UpdateData(false);
}当从服务器端向客户端发送数据时会发生数据丢失
如:(服务器端) 456789123->(客户端)4567참쳌쳌쳌쳌
{
if(!m_SocketList.IsEmpty())
{
UpdateData(true);
POSITION pos;
CClientSocket* pSocket=(CClientSocket*)m_SocketList.GetHead();
int count;
for(pos=m_SocketList.GetHeadPosition();pos!=NULL;)
{
pSocket=(CClientSocket*)m_SocketList.GetNext(pos);
pSocket->Send(sen,sen.GetLength()); }
count=sen.GetLength();
sen.Empty();
UpdateData(false);
}
else
MessageBox(_T("未建立有Socket连接,无法传递消息!"),_T("服务器程序"));
}客户端接收函数:
void CBITRevDlg::ReceiveMsg(CChatSocket *pSocket)
{wchar_t buff[1000];
int count;
count=pSocket->Receive(buff,1000);
buff[count]=0;b.Format(_T("%s"),buff);
UpdateData(false);
}当从服务器端向客户端发送数据时会发生数据丢失
如:(服务器端) 456789123->(客户端)4567참쳌쳌쳌쳌
解决方案 »
- 对话框加载位图
- 拖动画上去的图,旧的图为什么没擦除(带背景图和滚动条),HELP~
- 请教关于Windows下ASCII码的问题。
- 在线求助opengl纹理绑定问题
- 学mfc前有必要先看<windows程序设计>吗?!
- 标准工具栏---只支持16色。真是羞人啊?怎么解决呢?
- windows下一个内存地址可否用unsigned long变量装下?
- 已经得到IHtmlDocument2的接口,如何得到IE中某个EMBED flash的URL?
- 谁能介绍一下BoundsChecker的使用方法?
- 100分请教ado 的AddNew问题,十万火急!
- 求救!VC连接SQL Server 问题!急急急!
- 带图钉按扭的Dockbar
????
{
DECLARE_DYNAMIC(CClientSocket);
private:
CClientSocket(const CClientSocket& rSrc); // no implementation
void operator=(const CClientSocket& rSrc); // no implementation// Construction
public:
CClientSocket();// Attributes
public:
// Operations // Overridable callbacks
protected:
virtual void OnReceive(int nErrorCode);// Implementation
public:
virtual ~CClientSocket();#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};
void CClientSocket::OnReceive(int nErrorCode)
{
((CBITDlg*)(AfxGetApp()->m_pMainWnd))->ReceiveMsg(this);
CSocket::OnReceive(nErrorCode);
}class CListeningSocket : public CSocket
{
DECLARE_DYNAMIC(CListeningSocket);
private:
CListeningSocket(const CListeningSocket& rSrc); // no implementation
void operator=(const CListeningSocket& rSrc); // no implementation// Construction
public:
CListeningSocket();// Attributes
public:
// Overridable callbacks
protected:
virtual void OnAccept(int nErrorCode);// Implementation
public:
virtual ~CListeningSocket();#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};void CListeningSocket::OnAccept(int nErrorCode)
{ CClientSocket* pSocket=new CClientSocket();
CBITDlg* pMainWnd=
((CBITDlg*)(AfxGetApp()->m_pMainWnd));
if(pMainWnd->m_pSocket->Accept(*pSocket))
pMainWnd->m_SocketList.AddTail(pSocket);
else
delete pSocket;
CSocket::OnAccept(nErrorCode);
}
{
DECLARE_DYNAMIC(CChatSocket);// Construction
public:
CChatSocket();// Operations
public:
// Implementation
protected:
virtual void OnReceive(int nErrorCode);
};
void CChatSocket::OnReceive(int nErrorCode){
((CBITRevDlg*)(AfxGetApp()->m_pMainWnd))->ReceiveMsg(this);
CSocket::OnReceive(nErrorCode);
}
不过还是挺模糊的pSocket->Send(LPCTSTR(sen),sen.GetLength());--->pSocket->Send(LPCTSTR(sen),1000);