]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/libtransport/component.c
moved C code to a unified logging framework which currently supports syslogging and...
[Evergreen.git] / OpenSRF / src / libtransport / component.c
1 #include "transport_client.h"
2 #include "signal.h"
3
4
5 /*
6 void print_stuff(void* blah, char* data) {
7         fprintf(stderr, "Received from socket: %s\n", data);
8 }
9 */
10
11 /* connects and registers with the router */
12 int main( int argc, char** argv ) {
13
14
15
16         if( argc < 5 ) {
17                 osrfLogError( "Usage: %s <server> <port> <name> <secret>", argv[0] );
18                 return -1;
19         }
20
21         int port = atoi(argv[2]);
22         transport_client* client = client_init( argv[1], port, 1 );
23
24         // try to connect, allow 15 second connect timeout 
25         if( client_connect( client, argv[3], argv[4], "", 15, 1 ) ) 
26                 osrfLogInfo("Connected...\n");
27          else  {
28                 osrfLogError( "NOT Connected...\n" ); 
29                 return -1;
30          }
31         
32         transport_message* recv;
33         while( (recv=client_recv( client, -1)) ) {
34                 if( recv->is_error )
35                         fprintf( stderr, "\nReceived Error\t: ------------------\nFrom:\t\t"
36                                 "%s\nRouterFrom:\t%s\nBody:\t\t%s\nType %s\nCode %d\n=> ", 
37                                 recv->sender, recv->router_from, recv->body, recv->error_type, recv->error_code );
38                 else
39                         fprintf( stderr, "\nReceived\t: ------------------\nFrom:\t\t"
40                                 "%s\nRouterFrom:\t%s\nBody:\t\t%s\n=> ", recv->sender, recv->router_from, recv->body );
41                 transport_message* send = message_init( "Hello...", "", "123454321", recv->sender, argv[3] );
42                 client_send_message( client, send );
43                 message_free( recv );
44                 message_free( send );
45         }
46         return 0;
47
48 }
49
50
51
52