谁知道怎么用c++实现c/s远程关机命令,需要在下面的代码中添加什么
服务器部分:#include<winsock2.h>#pragmacomment(lib,"Wsock")#include<stdio.h>#defineDEFAULT_...
服务器部分:
#include<winsock2.h>
#pragma comment(lib,"Wsock")
#include<stdio.h>
#define DEFAULT_PORT 7038
void mian()
{
int iport=DEFAULT_PORT;
WSADATA wsaData;
SOCKET slisten,
sAccept;
int ilisten;
int isend;
char buf[]="hellow!i am your student";
struct sockaddr_in ser,
cli;
printf("-------------------------\n");
printf(" Server waiting \n");
printf("-------------------------\n");
if(WSAStartup(MAKEWORD(2,2),&wsaData)!=0)
{ printf("faild to load winsock.\n);
return;
}
sListen=socket(AF_INET,SOCK_STREAM,0);
ifListen=INVALID_SOCKET)
{
printf("socket()Faild:%d\n"),
WSAGetLasError())
return;
}
ser.sin_family=AF_INET;
ser.sin_port=htons(iport);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(sListen,(LPSOCKADDR)&ser,sizeof(ser))
==SOCKET_ERROR)
{ printf("bind()Faild:%d\n),
WSAGetLastError());
return;
if(listen(slisten,5)==SOCKET-ERROR)
{
printf("listen()Faild:%d\n,WSAGetError());
return;
}
ilen=sizeof(cli);
while(l)
{
sAccept=accept(sListen,(struct sockaddr*)
&cli,&ilen);
if(sAccept==INVALID_SOCKET)
{
printf("accept()Faild:%d\n"),
WSAGetLasError())
break;
}
printf(Accepted clientIP:[%s],port:[%d]\n",
inet_ntoa(cli,sin_addr),ntohs(cli.sin_port));
iSend=send(sAccept,buf,sizeof(buf),0);
if(iSend==SOCKET_ERROR)
{
printf("send( ) Failed.:%d\n",
WSAGetLastError( ));
break;
}
else if(iSend==0)
break;
else
{
printf("send( ) byte:%d\n",iSend);
printf("-----------------------------\n");
}
closesocket(sAccept);
}
closesocket(sListen);
WSACleanup( );
} 展开
#include<winsock2.h>
#pragma comment(lib,"Wsock")
#include<stdio.h>
#define DEFAULT_PORT 7038
void mian()
{
int iport=DEFAULT_PORT;
WSADATA wsaData;
SOCKET slisten,
sAccept;
int ilisten;
int isend;
char buf[]="hellow!i am your student";
struct sockaddr_in ser,
cli;
printf("-------------------------\n");
printf(" Server waiting \n");
printf("-------------------------\n");
if(WSAStartup(MAKEWORD(2,2),&wsaData)!=0)
{ printf("faild to load winsock.\n);
return;
}
sListen=socket(AF_INET,SOCK_STREAM,0);
ifListen=INVALID_SOCKET)
{
printf("socket()Faild:%d\n"),
WSAGetLasError())
return;
}
ser.sin_family=AF_INET;
ser.sin_port=htons(iport);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(sListen,(LPSOCKADDR)&ser,sizeof(ser))
==SOCKET_ERROR)
{ printf("bind()Faild:%d\n),
WSAGetLastError());
return;
if(listen(slisten,5)==SOCKET-ERROR)
{
printf("listen()Faild:%d\n,WSAGetError());
return;
}
ilen=sizeof(cli);
while(l)
{
sAccept=accept(sListen,(struct sockaddr*)
&cli,&ilen);
if(sAccept==INVALID_SOCKET)
{
printf("accept()Faild:%d\n"),
WSAGetLasError())
break;
}
printf(Accepted clientIP:[%s],port:[%d]\n",
inet_ntoa(cli,sin_addr),ntohs(cli.sin_port));
iSend=send(sAccept,buf,sizeof(buf),0);
if(iSend==SOCKET_ERROR)
{
printf("send( ) Failed.:%d\n",
WSAGetLastError( ));
break;
}
else if(iSend==0)
break;
else
{
printf("send( ) byte:%d\n",iSend);
printf("-----------------------------\n");
}
closesocket(sAccept);
}
closesocket(sListen);
WSACleanup( );
} 展开
2个回答
2014-10-12
展开全部
远程关机,需要使用Net命令吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询