-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_service.c
61 lines (52 loc) · 1.47 KB
/
test_service.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<stdio.h>
#include "finder.h"
void printfList(SubscribeServiceResult* res ){
int i;
printf("addr is:");
Node* list = res->addrList;
for( i=0;i<res->length;i++){
printf(" %s ",list->addr);
Node* n = list;
list = list->next;
}
printf("\n");
}
void freeRes(SubscribeServiceResult* res){
int i;
Node* list = res->addrList;
for( i=0;i<res->length;i++){
Node* n = list;
list = list->next;
free(n);
}
free(list);
free(res);
}
int main(){
InitCenter("http://10.1.87.70:6868","10.1.87.43:33223");
CommonResult rss = RegisterServiceWithAddr("guiderAllService", "gas","webgate-ws", "1.0.0","10.1.87.43:33223");
if (rss.code !=0){
printf("register service error,%s",rss.info);
free(rss.info);
return 0;
}
SubscribeServiceResult* res = SubscribeService("guiderAllService", "gas", "myservice","webgate-ws", "1.0.0");
if (res->code != 0){
printf("subscribe service error :%s",res->info);
free(res->info);
return 0;
}
printfList(res);
freeRes(res);
for (;;){
res = ListenService("guiderAllService", "gas","webgate-ws", "1.0.0",1);
if (res->code != 0){
printf("subscribe service error :%s",res->info);
free(res->info);
return 0;
}
printf("service address changed:->");
printfList(res);
freeRes(res);
}
}