1 | #include <stdio.h> |
---|
2 | #include <sys/types.h> |
---|
3 | #include <sys/socket.h> |
---|
4 | #include <netinet/in.h> |
---|
5 | #include <netdb.h> |
---|
6 | |
---|
7 | struct CE_Info { |
---|
8 | int numUtilities; |
---|
9 | int numParameters; |
---|
10 | int numObservables; |
---|
11 | }; |
---|
12 | |
---|
13 | struct Utility { |
---|
14 | char name[20]; |
---|
15 | char units[20]; |
---|
16 | char goal[20]; |
---|
17 | /* string name; |
---|
18 | string units; |
---|
19 | string goal;*/ |
---|
20 | float target; |
---|
21 | }; |
---|
22 | |
---|
23 | struct Affect { |
---|
24 | Utility * u; |
---|
25 | //string relation; |
---|
26 | char relation[20]; |
---|
27 | }; |
---|
28 | |
---|
29 | struct Parameter { |
---|
30 | /*string name; |
---|
31 | string units;*/ |
---|
32 | char name[20]; |
---|
33 | char units[20]; |
---|
34 | float min; |
---|
35 | int numAffects; |
---|
36 | Affect affection_list[10]; |
---|
37 | float max; |
---|
38 | float step; |
---|
39 | }; |
---|
40 | |
---|
41 | struct Observable { |
---|
42 | //string name; |
---|
43 | char name[20]; |
---|
44 | Affect affection_list[10]; |
---|
45 | int numAffects; |
---|
46 | }; |
---|
47 | |
---|
48 | // error handling |
---|
49 | void error(char *msg) |
---|
50 | { |
---|
51 | perror(msg); |
---|
52 | exit(0); |
---|
53 | } |
---|
54 | |
---|
55 | // main client socket |
---|
56 | int main(int argc, char *argv[]) |
---|
57 | { |
---|
58 | int sockfd, portno, n; |
---|
59 | struct sockaddr_in serv_addr; |
---|
60 | struct hostent *server; |
---|
61 | |
---|
62 | char buffer[256]; |
---|
63 | if (argc < 3) { |
---|
64 | fprintf(stderr,"usage %s hostname port\n", argv[0]); |
---|
65 | exit(0); |
---|
66 | } |
---|
67 | portno = atoi(argv[2]); |
---|
68 | sockfd = socket(AF_INET, SOCK_STREAM, 0); |
---|
69 | if (sockfd < 0) |
---|
70 | error("ERROR opening socket"); |
---|
71 | server = gethostbyname(argv[1]); |
---|
72 | if (server == NULL) { |
---|
73 | fprintf(stderr,"ERROR, no such host\n"); |
---|
74 | exit(0); |
---|
75 | } |
---|
76 | bzero((char *) &serv_addr, sizeof(serv_addr)); |
---|
77 | serv_addr.sin_family = AF_INET; |
---|
78 | bcopy((char *)server->h_addr, |
---|
79 | (char *)&serv_addr.sin_addr.s_addr, |
---|
80 | server->h_length); |
---|
81 | serv_addr.sin_port = htons(portno); |
---|
82 | if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) |
---|
83 | error("ERROR connecting"); |
---|
84 | |
---|
85 | printf("Please enter the message: "); |
---|
86 | bzero(buffer,256); |
---|
87 | fgets(buffer,255,stdin); |
---|
88 | n = write(sockfd,buffer,strlen(buffer)); |
---|
89 | if (n < 0) |
---|
90 | error("ERROR writing to socket"); |
---|
91 | bzero(buffer,256); |
---|
92 | |
---|
93 | // read back xml information |
---|
94 | int counter; |
---|
95 | Utility * uList[10] |
---|
96 | Parameter * pList[10]; |
---|
97 | Observable * oList[10]; |
---|
98 | CE_Info ce_info; |
---|
99 | |
---|
100 | // read unitilities |
---|
101 | // numUtilities |
---|
102 | n = read(sockfd,buffer,255); |
---|
103 | if (n < 0) |
---|
104 | error("ERROR reading from socket"); |
---|
105 | printf("%s\n",buffer); |
---|
106 | ce_info->numUtilities = atoi(buffer); |
---|
107 | printf("number of utilities: %d\n", ce_info->numUtilities); |
---|
108 | |
---|
109 | return 0; |
---|
110 | } |
---|