用CAsyncSocket类进行TCP通信时,客户端执行Connect()方法老是报错:
首先程序加入了#include "afxSock.h",AfxSocketInit();一。我是继承了两个CAsyncSocket类,服务端执行了:
Create(9001);
Listen();
然后在重载的OnAccept()事件中执行:
CAsyncSocket aSocket;
if (!Accept(aSocket))
{return;}
char aa[200];
memset(aa,0,200);
Receive(aa,200,FD_READ);
CAsyncSocket::OnAccept(nErrorCode);客户端:
CAsyncSocket cs;
if (!cs.Create())
{
AfxMessageBox("创建Socket失败!");
return;
}BOOL dd = cs.Connect("192.168.0.1",9001); //这是我本机的IP,,执行到这里,返回FALSE
if (!dd)
{
DWORD res = GetLastError(); //返回10035
AfxMessageBox("连接失败!");
return;
}请问这是为什么,几天了都没搞定
首先程序加入了#include "afxSock.h",AfxSocketInit();一。我是继承了两个CAsyncSocket类,服务端执行了:
Create(9001);
Listen();
然后在重载的OnAccept()事件中执行:
CAsyncSocket aSocket;
if (!Accept(aSocket))
{return;}
char aa[200];
memset(aa,0,200);
Receive(aa,200,FD_READ);
CAsyncSocket::OnAccept(nErrorCode);客户端:
CAsyncSocket cs;
if (!cs.Create())
{
AfxMessageBox("创建Socket失败!");
return;
}BOOL dd = cs.Connect("192.168.0.1",9001); //这是我本机的IP,,执行到这里,返回FALSE
if (!dd)
{
DWORD res = GetLastError(); //返回10035
AfxMessageBox("连接失败!");
return;
}请问这是为什么,几天了都没搞定
解决方案 »
- 自绘combox出现乱码.窗口按钮位置不正确
- CreateInstance(&pEvent)创建的实例需要client端手动释放吗?
- 两个进程通讯的问题。
- 请问能不能传我一些关于C\S通信方面的源码例子啊?谢谢!
- 请教各位有关ADO执行存储过程的一点小问题?
- 请问我想修改编译开关/GX和-GXo为-Gz,在那个选项里呀,我找了好久找不到,又急用,谁知道?
- 各位BOSS,我想做一个程序员,但不知道学什么好,可否指点一二.
- dicom的文件格式
- 重叠IO模型和完全端口模型
- 如果我在查看中添加绘图工具栏,如何才能显示/隐藏绘图工具栏菜单?
- SDI工程``我想动太的改变VIEW``请问怎样做?
- 时间函数问题
服务端执行了Create()方法,这自动调用了Bind(),
这个你应该知道吧??两个星星怎么来的?
我也调用了Bind,但也还是Connect失败,
Create then calls Bind to bind the socket to the specified address. The following socket types are supported: SOCK_STREAM Provides sequenced, reliable, full-duplex, connection-based byte streams. Uses the Transmission Control Protocol (TCP) for the Internet address family.
SOCK_DGRAM Supports datagrams, which are connectionless, unreliable packets of a fixed (typically small) maximum length. Uses the User Datagram Protocol (UDP) for the Internet address family.
跟端口无关,我试了好些端口,,to:zwzz541(木鱼)
就算Connect返回FALSE,我再调用Send(),但是服务端收不到信息
这个都不懂四个三角怎么混的????
或者谁帮我写一个用CAsyncSocket类,并使用TCP的通信方式的小程序
,发我email: [email protected]收到后100分相送...
说的应该对
又看了下你的程序!
CAsyncSocket aSocket;
if (!Accept(aSocket))
{return;}
char aa[200];
memset(aa,0,200);
Receive(aa,200,FD_READ); ——————aSocket.Receive(aa,200,FD_READ);
CAsyncSocket::OnAccept(nErrorCode);
看看
就是把下面的判断不要
if (!dd)
{
DWORD res = GetLastError(); //返回10035
AfxMessageBox("连接失败!");
return;
}
CAsyncSocket m_Sock;
m_Sock.Create();
int i = m_Sock.Connect("127.0.0.1",700);
Connect返回的就是0?(尽管和MSDN上面不相符合)
nErrorCode = 0表示成功
Use the select function to determine the completion of the connection request by checking to see if the socket is writeable.
If the application is using WSAAsyncSelect to indicate interest in connection events, then the application will receive an FD_CONNECT notification indicating that the connect operation is complete (successfully or not).
If the application is using WSAEventSelect to indicate interest in connection events, then the associated event object will be signaled indicating that the connect operation is complete (successfully or not).
if (WSAConnect(nSocket, sockAddr, socklen, NULL, NULL, NULL, NULL) == SOCKET_ERROR)
{
int wsaError = WSAGetLastError();
if (wsaError != WSAEWOULDBLOCK)
{
//连接失败
}
}