1 #include "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 fatal_handler( "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 info_handler("Connected...\n");
25 fatal_handler( "NOT Connected...\n" );
27 if( (pid=fork()) ) { /* parent */
29 signal(SIGINT, sig_int);
30 fprintf(stderr, "Listener: %d\n", getpid() );
35 while( fgets( buf, 299, stdin) ) {
38 buf[strlen(buf)-1] = '\0';
40 if( strcmp(buf, "exit")==0) {
41 client_free( client );
45 send = message_init( buf, "", "123454321", argv[4], NULL );
46 client_send_message( client, send );
51 fprintf(stderr, "Killing child %d\n", pid );
57 fprintf(stderr, "Sender: %d\n", getpid() );
59 transport_message* recv;
60 while( (recv=client_recv( client, -1)) ) {
62 fprintf( stderr, "\nReceived Error\t: ------------------\nFrom:\t\t"
63 "%s\nRouterFrom:\t%s\nBody:\t\t%s\nType %s\nCode %d\n=> ",
64 recv->sender, recv->router_from, recv->body, recv->error_type, recv->error_code );
66 fprintf( stderr, "\nReceived\t: ------------------\nFrom:\t\t"
67 "%s\nRouterFrom:\t%s\nBody:\t\t%s\n=> ", recv->sender, recv->router_from, recv->body );