Log In
New Account
  
 
Home My Page Project Tree Code Snippets Project Openings NUTSS
 
 
Summary Tracker Lists CVS Files
 

CVS | Administration

Annotation of libnutss/examples/NUTSS_app.c, revision 1.1

1.1     ! saikat      1: // NUTSS_app.cpp : Defines the entry point for the console application.
        !             2: //
        !             3:
        !             4: #include <stdio.h>
        !             5: #include <stdlib.h>
        !             6: #include "nutss.h"
        !             7:
        !             8: #ifdef WIN32
        !             9: #define snprintf _snprintf
        !            10: #endif
        !            11:
        !            12: #ifdef LINUX
        !            13: #include <errno.h>
        !            14: #endif
        !            15:
        !            16: #define EXCH 100000
        !            17: //#define TEST_ONE_PROCESS
        !            18:
        !            19: //int _tmain(int argc, _TCHAR* argv[])
        !            20: int main(int arg, char ** argv)
        !            21: {
        !            22:       int sendmode=0,rcvmode=0, i, one = 1, zero = 0;
        !            23:       SOCKET s, s2, s3;
        !            24:       struct sockaddr_ns nct;
        !            25:       int rval;
        !            26:       /*
        !            27:       char* proxy = "urbana:5060";  // "sip.nutss.net:5060";
        !            28:       char * user =  "ari"; //"saikat";
        !            29:       char *domain = "cs.cornell.edu"; // "nutss.net";
        !            30:       */
        !            31:
        !            32:       char* proxy =  "sip.nutss.net:5060";
        !            33:       char * user =  "ari1";
        !            34:       char *domain = "nutss.net";
        !            35:       char * pw = "password";
        !            36:       char* listeningUser = user;  //person to connect to
        !            37:       char * svcuname = "admin";
        !            38:       char * svcdomain = "nutss.net";
        !            39:       printf("test starting\n");
        !            40:
        !            41:
        !            42: #ifdef NUTSS_STATIC
        !            43:       printf("linking statically against nutss\n");
        !            44: #else
        !            45:       printf("linking dynamically against nutss\n");
        !            46: #endif
        !            47:
        !            48:
        !            49: #ifdef TEST_ONE_PROCESS
        !            50:       sendmode=rcvmode=1;
        !            51: #else
        !            52:       printf("note: one arg -->send, else receive\n\n");
        !            53:       if(arg > 1)
        !            54:       {
        !            55:      user = "ari2";   //our own username
        !            56:      sendmode = 1;
        !            57:       }
        !            58:       else
        !            59:      rcvmode =1;
        !            60: #endif
        !            61:
        !            62:       putenv("NUTSS_CERT=client.pem:password@root.pem");
        !            63:
        !            64:       nutss_config_set(NUTSS_CONFIG_USERNAME, user, strlen(user));
        !            65:       nutss_config_set(NUTSS_CONFIG_PROXYUSERNAME, user, strlen(user));
        !            66:       nutss_config_set(NUTSS_CONFIG_PROXYPASSWORD, pw, strlen(pw));
        !            67:       nutss_config_set(NUTSS_CONFIG_DOMAINNAME, domain, strlen(domain));
        !            68:       nutss_config_set(NUTSS_CONFIG_SIGPROXY, proxy, strlen(proxy));
        !            69:       nutss_config_set(NUTSS_CONFIG_OPT_SECURE, &zero, sizeof(zero));
        !            70:       nutss_config_set(NUTSS_CONFIG_SVCUSERNAME, svcuname, strlen(svcuname));
        !            71:       nutss_config_set(NUTSS_CONFIG_SVCDOMAINNAME, svcdomain, strlen(svcdomain));
        !            72:       nutss_init();
        !            73:
        !            74:       memset(&nct,0, sizeof(nct));
        !            75:      //now set up nct for the connect
        !            76:       nct.family = AF_NUTSS;
        !            77:
        !            78:       strncpy(nct.user, listeningUser, sizeof(nct.user));
        !            79:       strncpy(nct.domain, domain, sizeof(nct.domain));
        !            80:       strncpy(nct.service, "nutsstestapp", sizeof(nct.service));
        !            81:
        !            82:       if(rcvmode)
        !            83:       {
        !            84:      s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        !            85:  0 != nutss_bind(s, (struct sockaddr *)&nct, sizeof(nct)))
        !            86:      {
        !            87:     printf("failed to bind correctly\n");
        !            88:     exit(0);
        !            89:      }
        !            90:      else
        !            91:     listen(s, 10);
        !            92:       }
        !            93:
        !            94:       if(sendmode)
        !            95:       {
        !            96:      char buf[255];
        !            97:      memset(buf, 0, 255);
        !            98:      s2 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        !            99:
        !           100:      printf("trying to connect\n");
        !           101:      rval = nutss_connect(s2, &nct, sizeof(nct));
        !           102:      if(rval != 0)
        !           103:     printf("\nconnect failed [NUTSS_app], errno = %d \n", errno);
        !           104:      else
        !           105:     printf("connect returned success!\n");
        !           106:
        !           107:      for(i=0; i<EXCH; ++i)
        !           108:      {
        !           109:     int randwait;
        !           110:     rval = recv(s2, buf, 255, 0);
        !           111: #ifdef WIN32
        !           112:     randwait=  (rand() % 200);
        !           113:     Sleep(randwait+ 200);  //wait an average of 300 milis per round trip.
        !           114:
        !           115: #endif
        !           116:     if(rval > 0)
        !           117:     {
        !           118:    printf("\n----\nsender received message: %s\n----\n",buf);
        !           119:    snprintf(buf, 250, "hello, from the initator [%d]\n", i);
        !           120:    send(s2, buf, strlen(buf)+1, 0);
        !           121:     }
        !           122:     else
        !           123:     {
        !           124:    printf("\n---\nReceive failed\n--\n\n");
        !           125:    break;
        !           126:     }
        !           127:      }
        !           128:       }
        !           129:
        !           130:       if( rcvmode)
        !           131:       {
        !           132:      char buf[255];
        !           133:      s3 = nutss_accept(s, NULL, 0);
        !           134:      printf("connect succeeded; accept returned %08X\n", s3);
        !           135:
        !           136:      for( i=0; i<EXCH; ++i)
        !           137:      {
        !           138:     snprintf(buf, 250, "hello, from the receiver [%d]",i);
        !           139:     rval = send(s3, buf, strlen(buf)+1,0);
        !           140:     if(rval ==0)
        !           141:     {
        !           142:    printf("\n---\nSend failed\n--\n\n");
        !           143:    break;
        !           144:     }
        !           145:     memset(buf, 0, 255);
        !           146:     rval = recv(s3, buf, 255, 0);
        !           147:     if(rval > 0 && strlen(buf) > 0)
        !           148:    printf("\n\n--\n\nreceiver received: %s\n----\n", buf);
        !           149:     else
        !           150:     {
        !           151:    printf("\n\n--\n\nreceive failed\n---\n");
        !           152:    break;
        !           153:     }
        !           154:      }
        !           155:       }
        !           156:
        !           157:       printf("\ndone\n");
        !           158:       fflush(stdout);
        !           159: #ifdef WIN32
        !           160:       Sleep(3000000);
        !           161: #else
        !           162:       sleep(3000);
        !           163: #endif
        !           164:       return 0;
        !           165: }
        !           166:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
 

GForge.cis.cornell.edu is brought to you by

Cornell Computing and Information Science


Powered By GForge Collaborative Development Environment