testclient.c
1.35 KB
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
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "trbase.h"
#include "trcomm.h"
#include "trio.h"
#include "trevent.h"
#include "test_handler.h"
TR_INSTANCE(TR_LoggerSyslog, mylogger, {TR_LOGGER_INFO});
TR_INSTANCE(TR_LoggerStderr, mylogger2, {TR_LOGGER_INFO});
int
main (int argc, char * argv[])
{
TR_TcpSocket socket;
TR_Connection connection;
TR_SimpleClient client;
TR_Protocol protocol;
TR_ProtoMessageRaw message;
TR_RemoteData data;
TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger2);
socket = TR_new(TR_TcpSocket, TR_logger, "192.168.2.13", 5678, 0);
protocol = TR_new(TR_ProtocolRaw);
connection = TR_new(TR_Connection, socket, protocol);
TR_socketConnect((TR_Socket)socket);
TR_socketNonblock((TR_Socket)socket);
client = TR_new(TR_SimpleClient, connection);
message = (TR_ProtoMessageRaw)TR_protoCreateRequest(protocol, (TR_Socket)socket);
data = TR_new(TR_RemoteData, "test", sizeof("test"), (TR_Socket)socket);
message->data = data;
message = (TR_ProtoMessageRaw)TR_simpleClientIssue(
client,
(TR_ProtoMessage)message,
10000000);
printf("%s\n", ((TR_SizedData)message->data)->data);
TR_delete(message->data);
TR_delete(message);
puts("cleanup...");
TR_delete(client);
TR_delete(protocol);
TR_simpleClientClassCleanup();
TR_cleanup();
return 0;
}
// vim: set ts=4 sw=4: