-
Notifications
You must be signed in to change notification settings - Fork 1
/
Client.cpp
84 lines (60 loc) · 1.98 KB
/
Client.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// jaeger client adapted from https://github.com/jaegertracing/jaeger-client-cpp
// socket code adapted from https://www.geeksforgeeks.org/socket-programming-cc/
#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#define PORT 8080
#include <arpa/inet.h>
#include <unistd.h>
#include <iostream>
#include <yaml-cpp/yaml.h>
#include <jaegertracing/Tracer.h>
#include <jaegertracing/propagation/Propagator.h>
namespace {
void extractTracer() {
/*
TO DO
Assumes use of HTTP_HEADERS carrier format
Step 1: Initialise http server on agreed IP (localhost in this example) and port
Step 2: Get incoming request
Step 3: Set carrier using HTTP_HEADERS format with the incoming request
Step 4: Create a tracer
Step 5: Extract the span context from the carrier specifying the format as HTTP_HEADERS and initialise tracer
Step 6: start a child span on the tracer with the extracted span context
*/
}
} // anonymous namespace
int main(int argc, char
const * argv[]) {
extractTracer();
struct sockaddr_in address;
int sock = 0, valread;
struct sockaddr_in serv_addr;
char * hello = "Hello from client";
char buffer[1024] = {
0
};
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("\n Socket creation error \n");
return -1;
}
memset( & serv_addr, '0', sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
// Convert IPv4 and IPv6 addresses from text to binary form
if (inet_pton(AF_INET, "127.0.0.1", & serv_addr.sin_addr) <= 0) {
printf("\nInvalid address/ Address not supported \n");
return -1;
}
if (connect(sock, (struct sockaddr * ) & serv_addr, sizeof(serv_addr)) < 0) {
printf("\nConnection Failed \n");
return -1;
}
send(sock, hello, strlen(hello), 0);
printf("Hello message sent\n");
valread = read(sock, buffer, 1024);
printf("%s\n", buffer);
return 0;
}