标题:麻烦看看问题出在哪里,谢谢~
取消只看楼主
crazyfire
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-11-12
 问题点数:0 回复次数:1 
麻烦看看问题出在哪里,谢谢~

#include <iostream.h>
#include <stdio.h>
#include <Winsock2.h>
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested=MAKEWORD(1,1);
err=WSAStartup(wVersionRequested,&wsaData);/*初始化WINSOCK库*/
if(err!=0)
{ return;}/*如果调用成功则返回0,不成功即跳出*/
SOCKET sockSrv=socket(AF_INET,SOCK_STREAM,0); /*创建套接字,TCP/IP协议参数为AF_INET,

流套接字参数为SOCK_STRSAM,0为默认的连接方式*/
SOCKADDR_IN addrSrv;
addrSrv.sin_family=AF_INET;
addrSrv.sin_port=htons(6000); /*指明端口号*/
addrSrv.sin_addr.s_addr=htonl(INADDR_ANY); /*主机地址任意*/
bind(sockSrv,(SOCKADDR*)&addrSrv,sizeof(addrSrv)); /*绑定套接字与端口*/
listen(sockSrv,1);
SOCKADDR_IN addrClient;
int addrlen;
addrlen=sizeof(addrClient);
SOCKET socketClient=accept(sockSrv,(SOCKADDR*)&addrClient,&addrlen);/*创建另外1个套接字

socketClient与客户套界字建立连接*/
char recvBuf[50];
recv(socketClient,recvBuf,50,0);
cout << recvBuf << endl;
char sendBuf[50];
cin >> sendBuf;
int len;
len=strlen(sendBuf)+1;
send(socketClient,sendBuf,len,0);
if(send(socketClient,sendBuf,strlen(sendBuf)+1,0)<=len)
{cout << "send successful" << endl;}
closesocket(socketClient);
}
可以编译通过,用的VC6.0,但是不能运行,不知道理由...Linking...
connect.obj : error LNK2001: unresolved external symbol __imp__closesocket@4
connect.obj : error LNK2001: unresolved external symbol __imp__send@16
connect.obj : error LNK2001: unresolved external symbol __imp__recv@16
connect.obj : error LNK2001: unresolved external symbol __imp__accept@12
connect.obj : error LNK2001: unresolved external symbol __imp__listen@8
connect.obj : error LNK2001: unresolved external symbol __imp__bind@12
connect.obj : error LNK2001: unresolved external symbol __imp__htonl@4
connect.obj : error LNK2001: unresolved external symbol __imp__htons@4
connect.obj : error LNK2001: unresolved external symbol __imp__socket@12
connect.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
Debug/connect.exe : fatal error LNK1120: 10 unresolved externals
Error executing link.exe.这个是出错的地方...

[此贴子已经被作者于2006-11-22 16:09:00编辑过]

搜索更多相关主题的帖子: SOCK err include 套接字 麻烦 
2006-11-22 16:07
crazyfire
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-11-12
得分:0 

在project->setting->link->object/library modules里添加吗??
我在里面添加后VC6.0卡住了..卡在Link...请问怎么回事...

2006-11-22 19:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-104687-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.102299 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved