#include
"w_main.h"
/**
* File name : w_client.cpp
* Author : Edison
Chindrawly
* Course : CSCI 4330 TCP/IP Fall 2001
* Descp
: TCP Client collect information on
* the current
load of the csp server.
* It needs Port number that user
assigned
* from the command line. It also
requires
* that w_server's program is
running in
* all 10 CSP machine before
w_client can
* execute
* Usage
: ./w_client 1080
*/
void
main(int argc, char *argv[])
{
if(argc != 2)
{
cout<<"Usage: ./w_client
<port>"<<endl;
exit(0);
}
int port = atoi(argv[1]);
int socks;
struct hostent *host_entry;
struct sockaddr_in server;
char message[400];
char arrayOfCsp[10][19] = {"csp01.csci.unt.edu",
"csp02.csci.unt.edu",
"csp03.csci.unt.edu",
"csp04.csci.unt.edu",
"csp05.csci.unt.edu",
"csp06.csci.unt.edu",
"csp07.csci.unt.edu",
"csp08.csci.unt.edu",
"csp09.csci.unt.edu",
"csp10.csci.unt.edu" };
for(int i=0; i < 10; i++)
{
if((socks=socket(AF_INET,
SOCK_STREAM, IPPROTO_TCP)) == -1)
cerr<<"ERROR: opening socket"<<endl;
if((host_entry =
gethostbyname(arrayOfCsp[i])) == NULL)
cerr<<"ERROR: hostname"<<endl;
memset(&server,0,sizeof(server));
server.sin_family=AF_INET;
server.sin_port=htons(port);
server.sin_addr.s_addr = *((unsigned long
*)host_entry->h_addr);
if(connect(socks,(struct sockaddr *)&server, sizeof(server)) <
0)
cerr<<"ERROR:
connect"<<endl;
if(recv(socks,message,sizeof(message),0)< 0)
cerr<<"ERROR:
receive"<<endl;
cout<<arrayOfCsp[i]<<" load average:
"<<message<<endl;
close(socks);
}
}