Changeset 676 for trunk/user/tcp_client


Ignore:
Timestamp:
Nov 20, 2020, 12:11:35 AM (4 years ago)
Author:
alain
Message:

Introduce chat application to test the named pipes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/tcp_client/tcp_client.c

    r660 r676  
    3939        size = get_string( buffer , BUF_SIZE );
    4040
    41 /*
    42         strcpy( buffer , "blip\n" );
    43         printf("%s", buffer );
    44         size = 5;
    45 
    46         if( send( fdid , buffer , size , 0 ) != size )
    47         {
    48             printf("\n[server] chat error : cannotl sent message\n");
    49             return;
    50         }
    51 */
    52 
    5341        // exit chat function when local message is the "exit" string
    5442        if( strncmp( "exit" , buffer , 4 ) == 0 )
    5543        {
     44            printf("\n[tcp_client stop] local message is <exit> => return to main\n" );
    5645            return;
    5746        }
     
    6251        if( nbytes != size )
    6352        {
    64             printf("\n[server] send error => chat return to main\n");
     53            printf("\n[tcp_client error] cannot send => return to main\n");
    6554            return;
    6655        }
     
    7059
    7160        // receive server message
    72         nbytes =recv ( fdid, buffer, BUF_SIZE, 0 );
     61        nbytes = recv( fdid , buffer , BUF_SIZE , 0 );
    7362
    7463        if( nbytes < 0 )
    7564        {
    76             printf("\n\n[server] receive error => return to main\n" );
     65            printf("\n\n[tcp_client error] cannot receive => return to main\n" );
    7766            return;
    7867        }
    7968        else if( nbytes == 0 )
    8069        {
    81             printf("\n\n[server] receive EOF => return to main\n" );
     70            printf("\n\n[tcp_client stop] receive EOF => return to main\n" );
    8271            return;
    8372        }
     
    10594    // get  start cycle
    10695    get_cycle( &start_cycle );
    107     printf("\n[client] starts at cycle %d\n", (unsigned int)start_cycle );
     96    printf("\n[tcp_client] starts at cycle %d\n", (unsigned int)start_cycle );
    10897
    10998    pid = getpid();
     
    116105    if( fdid < 0 )
    117106    {
    118         printf("\n[client error] cannot create socket\n");
     107        printf("\n[tcp_client error] cannot create socket\n");
    119108        exit( 0 );
    120109    }
    121110    else
    122111    {
    123         printf("\n[client] created socket[%x,%d]\n", pid, fdid );
     112        printf("\n[tcp_client] created socket[%x,%d]\n", pid, fdid );
    124113    }
    125114
     
    134123    if( error )
    135124    {
    136         printf("\n[client error] bind failure on socketi[%x,%d]\n", pid, fdid );
     125        printf("\n[tcp_client error] bind failure on socketi[%x,%d]\n", pid, fdid );
    137126        exit( 0 );
    138127    }
    139128
    140     printf("\n[client] socket[%x,%d] bound : [%x,%x]\n",
     129    printf("\n[tcp_client] socket[%x,%d] bound : [%x,%x]\n",
    141130    pid, fdid, client_sin.sin_addr, (unsigned int)client_sin.sin_port );
    142131
     
    151140    if( error )
    152141    {
    153         printf("\n[client error] connect failure on socket[%x,%d]\n", pid, fdid );
     142        printf("\n[tcp_client error] connect failure on socket[%x,%d]\n", pid, fdid );
    154143        exit( 0 );
    155144    }
    156145
    157     printf("\n[client] socket[%x,%d] connected to server [%x,%x]\n",
     146    printf("\n[tcp_client] socket[%x,%d] connected to server [%x,%x]\n",
    158147    pid, fdid, server_sin.sin_addr, server_sin.sin_port );
    159148
     
    164153    close( fdid );
    165154
    166     printf("\n[client] closed socket[%x,%d]\n", pid, fdid );
     155    printf("\n[tcp_client] closed socket[%x,%d]\n", pid, fdid );
    167156
    168157    exit(0);
Note: See TracChangeset for help on using the changeset viewer.