Sunday, 15 April 2012

c - Client not able to send message to server -


I am new to programming socket programming. I am trying to create a server that has the ability to connect to multiple clients. However,

  1. My message server is not printed at the end. This means that the code "Do you want to send?" Prompt does not stop at

  2. The second message switch on the wired client (like) does not respond to my server. Same looks like

Edit 1 I have edited the code that sends a message to the customer. However, the server side prevents "error on ACCEPT: bad file descriptor", which I am unable to resolve.

Edit 2 My client is also sending another message, but my server does not receive it and does not print it, even if the error on acceptance has ended Ho.

  ----- Listen (sockfd, 5); Clilen = sizeof (cli_add); Int pid; While (1) {nzockfood = acceptable (sockfid, (structure sokadar *) and cli_ed, and cleanen); If (newsfold <0) {error ("error in accepting"); Exit (1); } Pid = fork (); If (pid & lt; 0) {error ("Error creating new process"); Exit (1); } If (pid == 0) {close (sockfd); // Read buffer from socket bargeo (buffer, 256); N = reading (Newsoffor, buffer, 255); If (n & lt; 0) {error ("error in reading"); Exit (1); } Printf ("Message:% s", Buffer); ----- Barge (buffer, 256); N = write (newsockfd, tmparray, strlen (tmparray)); If (n & lt; 0) error ("oops! Can not write"); Exit (0); } And {closed (newsfoked); }}  

and client.c is

  Int likes; While (1) {printf ("What to do? \ N1. Send \ n2.Exit \ n"); Scanf ("% d", & amp; option); Switch (Preferred) {Case 1: {Berzero (buffer, 256); Printf ("What do you want to send?"); Fgets (buffer, 255, stdin); Getchar (); N = write (sockfd, buffer, 255); If (n & lt; 0) error ("oops! Can not write"); Bzero (buffer, 256); N = reading (scoff, buffer, 255); If (n & lt; 0) error ("Oops! Can not read"); Printf ("Received Message:% s \ n", Buffer); break; } Case 2: {Return 0; }}}  


No comments:

Post a Comment