#include "includes.h" // client.cpp #include "internet_client.h" void main(int argc, char *argv[]) { char *line; int command; internet_client IC(argv[1],atoi(argv[2])); if (!IC.isOK()) exit(1); printf("saying hello to the server...\n"); IC.writeline("hello"); line=IC.readline(); printf("response from the server:\n \"%s\"\n",line); while (1) { printf("\n"); printf("Select: 1> Say hello to the server again\n"); printf(" 2> Ask the server what the time is\n"); printf(" 3> Ask the server how it is feeling\n"); printf(" 4> Tell the server to terminate\n"); printf(" 5> Disconnect from the server\n"); printf("command: "); int n=scanf("%d",&command); if (n==0) continue; switch (command) { case 1: printf("saying hello to the server...\n"); IC.writeline("hello"); line=IC.readline(); printf("response from the server:\n \"%s\"\n",line); break; case 2: printf("asking the server what time it is...\n"); IC.writeline("what time is it?"); line=IC.readlineLC(); if (line[0]=='i' && line[1]=='t' && line[2]==' ' && line[3]=='i' && line[4]=='s' && line[5]==' ') printf("The server said it is now %s.\n", line+6); else printf("The server made an inappropriate response\n"); break; case 3: printf("asking the server how it feels...\n"); IC.writeline("how are you?"); line=IC.readline(); printf("the server replied:\n \"%s\"\n",line); break; case 4: printf("telling the server to stop...\n"); IC.writeline("drop dead"); line=IC.readline(); printf("response from the server:\n \"%s\"\n",line); break; case 5: printf("saying goodbye to the server...\n"); IC.writeline("goodbye"); line=IC.readline(); printf("response from the server:\n \"%s\"\n",line); IC.disconnect(); } if (command==5) break; } printf("End of interaction.\n"); }