大家帮我看看这段代码啊,怎么通不过啊在VC6中?小弟我刚学SOCKET编程,在线等
// Server.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "afxwin.h"
#include "process.h"
#include "winsock.h"
#include "iostream.h"
#define MAX 50
//////////////////////////////////////
UINT thread(LPVOID p);
int getcount(void);
void sendtoall(SOCKET s, char *buff);
//////////////////////////////////////
SOCKET msgsock[MAX];
SOCKET sock;
struct sockaddr_in serv;
int addlen;
int main(int argc, char* argv[])
{
WSADATA wsadata;
cout<<"Initing...."<<endl;
WSAStartup(0x0101,&wsadata);
sock = socket(AF_INET,SOCK_STREAM,NULL);
if(sock == INVALID_SOCKET)
{
cout<<"Initialize Field"<<endl;
return 0;
}
cout<<"Initialize Succeed"<<endl;
serv.sin_addr.s_addr = htonl(INADDR_ANY);
serv.sin_family = AF_INET;
serv.sin_port = htons(5000);
addlen = sizeof(serv);
if( bind(sock,(sockaddr *)&serv,addlen) != 0 )
{
cout<<"bind socket error!"<<endl;
return 0;
}
if( listen(sock,5) != 0 )
{
cout<<"listen socket error!"<<endl;
return 0;
}
_beginthread(&thread,0,0);
return 0;
}
UINT thread(LPVOID p)
{
int loop = 1;
int msgcount = getcount();
int s;
char buff[100];
if(msgcount == -1)
loop = 0;
if( loop )
{
s = 1;
msgsock[msgcount] = accept(sock,(sockaddr *)&serv,&addlen);
if ( msgsock[msgcount] == INVALID_SOCKET)
{
cout<<"accept socket error!"<<endl;
}
else
{
_beginthread(&thread,0,0);
cout<<"connect succeed!"<<endl;
while( s != SOCKET_ERROR )
{
s = recv(msgsock[msgcount],buff,100,0);
if( s != SOCKET_ERROR )
sendtoall(msgsock[msgcount],buff);
}
send(msgsock[msgcount],"Disconnected",100,0);
closesocket(msgsock[msgcount]);
msgsock[msgcount] = NULL;
}
}
_endthread();
return 0;
}
int getcount(void)
{
for(int i=0; i<MAX; i++)
{
if(msgsock[i] == NULL)
return i;
}
return -1;
}
void sendtoall(SOCKET s, char *buff)
{
for(int i=0; i<MAX; i++)
{
if(msgsock[i] != NULL && msgsock[i] != s)
send(msgsock[i],buff,100,0);
}
}
我已经加了 wsock32.lib MSVCRT.LIB LIBCMT.LIB
怎么通不过啊
错误信息是:
D:\vc\SERVER\Server.cpp(60) : error C2065: '_beginthread' : undeclared identifier
D:\vc\SERVER\Server.cpp(103) : error C2065: '_endthread' : undeclared identifier