描述:
哪位知道在VC中如何使用Winsock控件?哪里有关于VC中使用Winsock控件的全面介绍?
在OnConnectionRequest事件中我加入了一个ctrlWinsock.Accept(requestID)接受远程连接(详见下面源代码),但是测试时,发现客户端刚连接上,马上server端就断了,再去连接还会重复这个现象,这是怎么回事?
下面是部分代码:
void CMyTest::OnButtonListen()
{
// TODO: Add your control notification handler code here
VARIANT localport;
VARIANT localip;
CString strport;
CString strip;
VARIANT vtCommand;
CString m_command;
VARIANT vtData;
VARIANT vtType;
localport.vt=VT_BSTR;
localip.vt=VT_BSTR;
strport="1234";
strip="192.168.1.1";
vtCommand.vt=VT_BSTR;
m_command="Server Send";
vtData.vt=VT_BSTR;
vtType.vt=VT_ERROR;
localport.bstrVal=strport.AllocSysString();
localip.bstrVal=strip.AllocSysString();
m_ctrlWinsock.SetProtocol(1);// 选择UDP协议,1=UDP, 0=TCP
m_ctrlWinsock.Bind(localport, localip);
m_ctrlWinsock.Listen();
}
void CMyTest::OnConnectionRequestWinsockServer(long requestID)
{
// TODO: Add your control notification handler code here
m_ctrlWinsock.Accept(requestID);
}
void CMyTest::OnButtonStop()
{
// TODO: Add your control notification handler code here
m_ctrlWinsock.Close();
}
void CMyTest::OnCloseWinsockServer()
{
// TODO: Add your control notification handler code here
m_ctrlWinsock.Close();
m_ctrlWinsock.Listen();
}
解决方案1:
http://www.netyi.net/in.asp?id=lockllb 在这里有计算机的大多数的答案~学计算机的好地方~
解决方案2: http://www.vchelp.net/vchelp/zart/wsctrl.asp?type_id=36&class_id=1&cata_id=5&article_id=122&search_term=
VISCAL C++下WINSOCK CONTROL类(ACTIVEX)的使用