急!!!!! winSock服务器程序
#include<PROCESS.H>#include<windows.h>
#include<winsock.h>
#include<sys/types.h>
#include<fcntl.h>
#include<wsipx.h>
#include<stdio.h>
#define SERV_TCP_PORT 90
#define SERV_HOST_ADDR "10.60.46.2"
int sockfd;
DWORD ClientThread(void *pVoid)
{
int nRet;
char szBuf[1024];
memset(szBuf,0,sizeof(szBuf)); /*将szBuf全部清零*/
nRet=recv((SOCKET)pVoid,szBuf,sizeof(szBuf),0);
if(nRet == INVALID_SOCKET){
printf("recv()");
closesocket(sockfd);
closesocket((SOCKET)pVoid);
return 0;
}
printf("\nData received:%\n",szBuf);
strcpy(szBuf,"From the Server");
nRet=send((SOCKET)pVoid,szBuf,strlen(szBuf),0);
closesocket((SOCKET)pVoid);
return 0;
}
int main()
{
int clilen;
int pHandle=-1;
struct sockaddr_in serv_addr;
SOCKET socketClient;
DWORD ThreadAddr;
HANDLE dwClientThread;
SOCKADDR_IN SockAddr;
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
if(WSAStartup(wVersionRequested,&wsaData)){
printf("WSAStartup failed %s\n", WSAGetLastError());
return -1;
}
if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
printf("server:can't open stream socker\n");
memset((char *)&serv_addr,0,sizeof(struct sockaddr_in));
serv_addr.sin_family=AF_INET;
serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
serv_addr.sin_port=htons(SERV_TCP_PORT);
if(bind(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr))<0)
printf("server:can't bind local address");
listen(sockfd,5);
while(1){
clilen = sizeof(SOCKADDR_IN);
socketClient = accept(sockfd,(LPSOCKADDR)&SockAddr,&clilen);
if(socketClient == INVALID_SOCKET){
printf("accpet faild!\n");
break;
}
printf("Connection accepted on socket:%d from:%s\n",socketClient,inet_ntoa(SockAddr.sin_addr));
dwClientThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&ClientThread,(void *)socketClient,0,&ThreadAddr);
if(!dwClientThread)
printf("Cannot start client thread..");
CloseHandle((HANDLE)dwClientThread);
}
WSACleanup();
return 0;
}
这是一个服务器程序我在编译运行时出现下面的错误,请问是什么原因? 初学网络编程请各位高手帮忙!!!!!!!!!!!!
Compiling...
winsock.cpp
D:\vc\MSDev98\MyProjects\winsock\winsock.cpp(10) : warning C4005: 'SERV_HOST_ADDR' : macro redefinition
d:\vc\msdev98\myprojects\winsock\winsock.cpp(0) : see previous definition of 'SERV_HOST_ADDR'
Linking...
winsock.obj : error LNK2001: unresolved external symbol _send@16
winsock.obj : error LNK2001: unresolved external symbol _closesocket@4
winsock.obj : error LNK2001: unresolved external symbol _recv@16
winsock.obj : error LNK2001: unresolved external symbol _WSACleanup@0
winsock.obj : error LNK2001: unresolved external symbol _inet_ntoa@4
winsock.obj : error LNK2001: unresolved external symbol _accept@12
winsock.obj : error LNK2001: unresolved external symbol _listen@8
winsock.obj : error LNK2001: unresolved external symbol _bind@12
winsock.obj : error LNK2001: unresolved external symbol _htons@4
winsock.obj : error LNK2001: unresolved external symbol _htonl@4
winsock.obj : error LNK2001: unresolved external symbol _socket@12
winsock.obj : error LNK2001: unresolved external symbol _WSAGetLastError@0
winsock.obj : error LNK2001: unresolved external symbol _WSAStartup@8
Debug/winsock.exe : fatal error LNK1120: 13 unresolved externals
执行 link.exe 时出错.
winsock.exe - 1 error(s), 0 warning(s)