1 #include <opensrf/transport_client.h>
5 void sig_int( int sig ) {
6 fprintf(stderr, "Killing child %d\n", pid );
10 /* connects and registers with the router */
11 int main( int argc, char** argv ) {
14 osrfLogError( OSRF_LOG_MARK, "Usage: %s <username> <host> <resource> <recipient> \n", argv[0] );
18 transport_message* send;
19 transport_client* client = client_init( argv[2], 5222, 0 );
21 // try to connect, allow 15 second connect timeout
22 if( client_connect( client, argv[1], "jkjkasdf", argv[3], 15, AUTH_DIGEST ) )
23 osrfLogInfo(OSRF_LOG_MARK, "Connected...\n");
25 osrfLogError( OSRF_LOG_MARK, "NOT Connected...\n" );
29 if( (pid=fork()) ) { /* parent */
31 signal(SIGINT, sig_int);
32 fprintf(stderr, "Listener: %ld\n", (long) getpid() );
34 osrf_clearbuf(buf, sizeof(buf));
37 while( fgets( buf, sizeof(buf), stdin) ) {
40 buf[strlen(buf)-1] = '\0';
42 if( strcmp(buf, "exit")==0) {
43 client_free( client );
47 send = message_init( buf, "", "123454321", argv[4], NULL );
48 client_send_message( client, send );
51 osrf_clearbuf(buf, sizeof(buf));
53 fprintf(stderr, "Killing child %d\n", pid );
59 fprintf(stderr, "Sender: %ld\n", (long) getpid() );
61 transport_message* recv;
62 while( (recv=client_recv( client, -1)) ) {
64 fprintf( stderr, "\nReceived Error\t: ------------------\nFrom:\t\t"
65 "%s\nRouterFrom:\t%s\nBody:\t\t%s\nType %s\nCode %d\n=> ",
66 recv->sender, recv->router_from, recv->body, recv->error_type, recv->error_code );
68 fprintf( stderr, "\nReceived\t: ------------------\nFrom:\t\t"
69 "%s\nRouterFrom:\t%s\nBody:\t\t%s\n=> ", recv->sender, recv->router_from, recv->body );