socket创建连接失败?

beterocky 2002-07-21 11:20:15
/*********************************************************************/
/*********************** Sever *************************/
/*********************************************************************/
int rc;
WSADATA wsadata;
SOCKADDR_IN addr;
unsigned long sock;
char data[100];
int test;

strcpy(data,"Hello");
rc = WSAStartup(2, &wsadata);
if(rc)
{
AfxMessageBox("WSAStartup FAILED: err=%d\n", GetLastError());
_endthread();
}

addr.sin_family = AF_INET;
addr.sin_port = 2000;
addr.sin_addr.S_un.S_addr = inet_addr("192.168.1.1");
sock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,0,WSA_FLAG_OVERLAPPED);
bind(sock,(struct sockaddr *)&addr,sizeof(addr));
listen(sock,SOMAXCONN);
accept(sock,(struct sockaddr *)&addr,NULL);
test = WSAGetLastError();
test = send(sock,data, 5,0);
test = WSAGetLastError();
WSACleanup();
/*********************************************************************/
/*********************** Client ************************/
/*********************************************************************/
int rc;
WSADATA wsadata;
SOCKADDR_IN addr;
unsigned long sock;
char data[100];

rc = WSAStartup(2, &wsadata);
if(rc)
{
AfxMessageBox("WSAStartup FAILED: err=%d\n", GetLastError());
}

addr.sin_family = AF_INET;
addr.sin_port = 2000;
addr.sin_addr.S_un.S_addr = inet_addr("192.168.1.1");
sock = WSASocket(AF_INET,SOCK_STREAM,0,NULL,0,WSA_FLAG_OVERLAPPED);

int test = connect(sock,(struct sockaddr *)&addr,sizeof(addr));

recv(sock,data,6,0);
WSACleanup();

Client的connect()消息Server能收到,只是当Server发送数据时,报错,说创建连接失败?
问题出在哪里咧?
...全文
315 点赞 收藏 回复
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复

还没有回复,快来抢沙发~

发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告
暂无公告