Changeset 66 for vtcross

Show
Ignore:
Timestamp:
11/20/08 22:00:50 (16 years ago)
Author:
ahe
Message:

update socket

Location:
vtcross/branches/trnewman/CR_shell
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • vtcross/branches/trnewman/CR_shell/Makefile

    r62 r66  
    33# 
    44 
    5 TESTS = cognitive_radio 
    6 all: $(TESTS) 
     5TESTS = cognitive_radio cognitive_engine 
     6#CTESTS = client 
     7all: $(TESTS) $(CTESTS) 
    78 
    89CC = g++ 
     10cc = gcc 
    911CFLAGS = -Wall -O3 
    1012LDFLAGS = -lm -ldl -pthread -lnsl 
     
    3032        $(CC) $(CFLAGS) $(OBJS) $(SOCKET_OBJS) $(LDFLAGS) $< -o $@ 
    3133 
     34$(CTESTS) : % : src/main_%.c 
     35                $(cc) $(CFLAGS) $(LDFLAGS) $< -o $@ 
     36 
    3237clean: 
    3338        rm -rf *.o socket/*.o $(TESTS) 
  • vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp

    r65 r66  
    215215} 
    216216 
    217 int ReceiveMessage(int socketfd) { 
     217int ReceiveMessage(int socketfd, string message) { 
    218218         
    219219        char buffer[256]; 
     
    221221 
    222222        // Clear incoming data buffer 
    223         bzero(buffer,256); 
     223    bzero(buffer,256); 
    224224     
    225225        // Wait for incoming message 
     
    227227         
    228228        // Print message 
    229         if (n > 0) printf("Here is the message: %s\n",buffer); 
    230  
    231         return n; 
     229    if (n > 0)  
     230        printf("Here is the message: %s\n",buffer); 
     231    //printf("n = %d\n",n); 
     232         
     233    return n; 
    232234} 
    233235 
     
    236238 
    237239        // Write message back to client 
    238         n = send(socketfd,message.c_str(),(message.size()+1),MSG_NOSIGNAL); 
    239         return n; 
    240  
     240    n = send(socketfd,message.c_str(),(message.size()+1),MSG_NOSIGNAL); 
     241         
     242    return n; 
    241243} 
    242244 
     
    245247        char counter[55]; 
    246248        char var[50]; 
    247         int k; 
    248  
    249  
    250 //      while(1) { 
     249 
     250     
     251    while(1) { 
    251252                // Send parameters from struct 
    252253                sprintf(counter,"%d",ce_info->numUtilities); 
    253254                SendMessage(socketfd,counter); 
    254255                 
    255                 for(i = 0; i < ce_info->numUtilities ; i++) { 
     256                // utilities 
     257        for(i = 0; i < ce_info->numUtilities; i++) { 
    256258                        SendMessage(socketfd,uList[i]->name); 
    257259                        SendMessage(socketfd,uList[i]->units); 
     
    260262                        SendMessage(socketfd,var); 
    261263                } 
    262                 sprintf(counter,"%i",ce_info->numParameters); 
     264 
     265                // parameters 
     266        sprintf(counter,"%i",ce_info->numParameters); 
    263267                SendMessage(socketfd,counter); 
    264268                for(i = 0; i < ce_info->numParameters; i++) { 
     
    279283                        } 
    280284                } 
     285 
     286        // observables 
    281287                sprintf(counter,"%i",ce_info->numObservables); 
    282288                SendMessage(socketfd,counter); 
     
    291297                        } 
    292298                } 
    293 /*               
     299         
    294300 
    295301                // Receive a message 
    296                 n = ReceiveMessage(socketfd);    
    297                 if (n < 0) { 
    298                         printf("ERROR reading from socket"); 
     302        string message; 
     303                n = ReceiveMessage(socketfd, message); 
     304        //cout << message << endl; 
     305 
     306 
     307        //printf("n = %d\n", n); 
     308                /*if (n < 0) { 
     309                        printf("ERROR reading from socket\n"); 
    299310                        close(socketfd); 
    300311                        return; 
     
    303314                        printf("Client has closed the connection.\n"); 
    304315                        return; 
    305                 } 
    306 */       
    307 //      } 
     316                }*/ 
     317         
     318    } 
    308319} 
    309320 
     
    328339        clilen = sizeof(cli_addr); 
    329340 
    330         while(1) { 
     341        //while(1) { 
    331342                newsockfd = accept(sockfd,  
    332343                        (struct sockaddr *) &cli_addr,  
     
    337348                // Begin parsing the messages 
    338349                StartMessaging(newsockfd,uList, pList, oList, ce_info); 
    339         } 
     350        //} 
    340351        return 0; 
    341352} 
     
    379390        } else { 
    380391                // In parent process - open cognitive engine port. 
    381                 StartShell(30000,uList, pList, oList, &ce_info); 
     392                StartShell(30003,uList, pList, oList, &ce_info); 
    382393        }  
    383394         
  • vtcross/branches/trnewman/CR_shell/src/socket/simple_client_main.cpp

    r65 r66  
    99    { 
    1010 
    11       ClientSocket client_socket ( "localhost", 30000 ); 
     11      ClientSocket client_socket ( "localhost", 30001 ); 
    1212 
    1313      std::string reply;