Friday, 15 March 2013

multithreading - C - Socket Chat Server with thread - Nickname array -


I am doing chat server using socket and thread in C, but I have a different problem: - I'm not enabled I am sending a message to the client to send a message to use their nickname - and attach client adder aliases is a problem. Can you help me on this?

How can I fix alias: client alias * / if (strcmp (clients_nick [client], "") == 0) {write (fd, msg, strlen (msg) * Asks for sizeof (char); Int rc = Read (FD, Buff, Buffle); If (RC & gt; 0) {/ * delete character \ n * / buf [strlen (buf) - 1] = '\ 0'; Snprintf (clients_nick [client], MAX_NICK_LENGTH - 1, "% s", buf); }}

How do I send the message: void client_write_message (char * msg, int client_sender, int client_receiver) {char * buffer; Buffer = coloc (buffalo, size (four));

  snprintf (buffer, buffalo, "[% s", clients_nick [client_seender]); Buffer [Stellen (clients_nick [client_seender]]] = ']'; Snprintf (buffer, buffalo, "% s", msg); Write (client [client_recure], msg, strlen (msg) * size (four)); Buffer [0] = '\ 0'; Free (buffer);    

This is incorrect:

  buf [ Strlen (buf) - 1] = '\ 0'; As a null terminator is not attached, such as  strlen ()  depends on  strlen ()  by   

Is unknown and may result in reaching out of range at buf . Remove the zero terminator assignment and replace it with:

  if (RC> 0) {snprintf (clients_nick [client], MAX_NICK_LENGTH - 1, "%. *. * S ', rc, Buf);}   

is the result of reading () ; the number of lessons taught, stored in RC in the post code, And the format specifier %. * S uses a length and buffer and does not need to cancel the buffer.

No comments:

Post a Comment