| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1230 人关注过本帖
标题:急!!!!! winSock服务器程序
取消只看楼主 加入收藏
酷儿
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-15
收藏
 问题点数:0 回复次数:3 
急!!!!! 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)
搜索更多相关主题的帖子: 服务器 winSock 程序 
2008-05-08 20:30
酷儿
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-15
收藏
得分:0 
各位帮下忙啊!!
2008-05-08 20:40
酷儿
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-15
收藏
得分:0 
太感谢了!!!
能给我具体讲一下那是做什么的吗?
2008-05-09 19:39
酷儿
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-15
收藏
得分:0 
谢了
2008-05-10 11:38
快速回复:急!!!!! winSock服务器程序
数据加载中...
 
   



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

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