Changeset 676 for trunk/user/tcp_client/tcp_client.c
- Timestamp:
- Nov 20, 2020, 12:11:35 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/tcp_client/tcp_client.c
r660 r676 39 39 size = get_string( buffer , BUF_SIZE ); 40 40 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 53 41 // exit chat function when local message is the "exit" string 54 42 if( strncmp( "exit" , buffer , 4 ) == 0 ) 55 43 { 44 printf("\n[tcp_client stop] local message is <exit> => return to main\n" ); 56 45 return; 57 46 } … … 62 51 if( nbytes != size ) 63 52 { 64 printf("\n[ server] send error => chatreturn to main\n");53 printf("\n[tcp_client error] cannot send => return to main\n"); 65 54 return; 66 55 } … … 70 59 71 60 // receive server message 72 nbytes = recv ( fdid, buffer, BUF_SIZE, 0 );61 nbytes = recv( fdid , buffer , BUF_SIZE , 0 ); 73 62 74 63 if( nbytes < 0 ) 75 64 { 76 printf("\n\n[ server] receive error=> return to main\n" );65 printf("\n\n[tcp_client error] cannot receive => return to main\n" ); 77 66 return; 78 67 } 79 68 else if( nbytes == 0 ) 80 69 { 81 printf("\n\n[ server] receive EOF => return to main\n" );70 printf("\n\n[tcp_client stop] receive EOF => return to main\n" ); 82 71 return; 83 72 } … … 105 94 // get start cycle 106 95 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 ); 108 97 109 98 pid = getpid(); … … 116 105 if( fdid < 0 ) 117 106 { 118 printf("\n[ client error] cannot create socket\n");107 printf("\n[tcp_client error] cannot create socket\n"); 119 108 exit( 0 ); 120 109 } 121 110 else 122 111 { 123 printf("\n[ client] created socket[%x,%d]\n", pid, fdid );112 printf("\n[tcp_client] created socket[%x,%d]\n", pid, fdid ); 124 113 } 125 114 … … 134 123 if( error ) 135 124 { 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 ); 137 126 exit( 0 ); 138 127 } 139 128 140 printf("\n[ client] socket[%x,%d] bound : [%x,%x]\n",129 printf("\n[tcp_client] socket[%x,%d] bound : [%x,%x]\n", 141 130 pid, fdid, client_sin.sin_addr, (unsigned int)client_sin.sin_port ); 142 131 … … 151 140 if( error ) 152 141 { 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 ); 154 143 exit( 0 ); 155 144 } 156 145 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", 158 147 pid, fdid, server_sin.sin_addr, server_sin.sin_port ); 159 148 … … 164 153 close( fdid ); 165 154 166 printf("\n[ client] closed socket[%x,%d]\n", pid, fdid );155 printf("\n[tcp_client] closed socket[%x,%d]\n", pid, fdid ); 167 156 168 157 exit(0);
Note: See TracChangeset
for help on using the changeset viewer.