小弟编的程序(有问题),可是不知道问题在哪。(求助)
数据推动力 2003-08-24 08:26:49 #include "iostream.h"
#include "winsock2.h"
#include "windows.h"
int main()
{
SOCKET sListen,sClient;
WSADATA wsd;
int iAddrSize;
struct sockaddr_in local,client;
char szBuff='\0',
*szCurrent,
*szWait;
int All=0,
Current=0,
Wait=0;
if(WSAStartup(MAKEWORD(2,2),&wsd)!=0)
{
cout<<"Failed to load Winsock!"<<endl;
return 1;
}
sListen=socket(AF_INET,SOCK_STREAM,IPPROTO_IP);
if(sListen==SOCKET_ERROR)
{
cout<<"Socket() failed"<<endl;
return 1;
}
local.sin_addr.s_addr=inet_addr("127.0.0.1");
local.sin_family=AF_INET;
local.sin_port=htons(6001);
if(bind(sListen,(struct sockaddr *)&local,sizeof(local))==SOCKET_ERROR)
{
cout<<"bind() failed."<<endl;
return 1;
}
while(1)
{
listen(sListen,6);
iAddrSize=sizeof(client);
sClient=accept(sListen,(struct sockaddr *)&client,&iAddrSize);
if(sClient==INVALID_SOCKET)
{
cout<<"accept() failed."<<endl;
break;
}
cout<<"Now connecting:"<<inet_ntoa(client.sin_addr)<<endl;
recv(sClient,(char*)szBuff,1,0);
if(szBuff=='*')
{
All++;
Wait=All-Current;
szWait=(char*)Wait;
send(sClient,szWait,strlen(szWait),0);
}
if(szBuff=='#')
{
Current++;
cout<<"No."<<Current<<"To:"<<inet_ntoa(client.sin_addr)<<endl;
szCurrent=(char*)Current;
send(sClient,szCurrent,strlen(szCurrent),0);
}
if(szBuff=='$')
{
cout<<"All:"<<All<<endl;
cout<<"Current:"<<Current<<endl;
cout<<"Wait:"<<Wait<<endl;
break;
}
}
closesocket(sListen);
WSACleanup();
return 0;
}
请指教。