title: C Program, recv() error: Connection reset by peer
body: <p>I have some Problems using the recv() and send() functions.</p>
  
  <p>here's my code:</p>
  
  <pre><code>#include "performConnection.h"
  #include "errno.h"
  
  
  
  //checks if the first arguement of an answer is "+"
  bool checkPlus(char buffer[]){
  int position = strcspn(buffer,"+");
  if (position==0){
      return true;
  }
  else{
      return false;
  }
  
  }
  
  int performConnection(int socketDescriptor){
  bool check;
  char buffer[256];
  memset(&amp;buffer, 0, sizeof(buffer));
  char string[1024];
  memset(&amp;string, 0, sizeof(string));
  int n;                      //Bytes received/send
  
  
  
  
  //receiving data from server//accepting connections
  n = recv(socketDescriptor, buffer, 255,0);
  if(n&lt;0){
      perror("recv() failed");
      printf("Exiting program");
  
      return EXIT_FAILURE;                    //exit program if receive failed
  }
  else{
      check = checkPlus(buffer);  //+ check for positive answer
      if (check==false){
          perror("failure");
          return EXIT_FAILURE;    //exit program if -
      }
  
  }
  printf("%s\n", buffer);
  memset(buffer, 0, sizeof(buffer));
  
  
  
  //send GAMEVERSION to server
  n = send(socketDescriptor,GAMEVERSION, 255, 0);
  if(n&lt;0){
      perror("send() failed");
      printf("exiting program");
      return EXIT_FAILURE;                    //exit program if send() fails
  }
  
  printf("Gameversion: %i, %s",n, GAMEVERSION);
  
  //receive server data
  n = recv(socketDescriptor, buffer, 255, 0);
   if(n&lt;0){
      perror("recv() failed");
      printf("Exiting program");
  
      return EXIT_FAILURE;                    //exit program if recv() fails
  }
  else{
      check = checkPlus(buffer);  //+ check for positive answer
      if (check==false){
          perror("failure");
          return EXIT_FAILURE;                //exit program if negative answer
      }
  }
  
  printf("%s\n", buffer);
  memset(&amp;buffer,0, sizeof(buffer));
  
  
  
      strcpy(buffer,"ID K.GcY_EqHAs\n");
      printf("%s\n",buffer);
      n = send(socketDescriptor, buffer, 255,0);
      if(n&lt;0){
          perror("send() failed");
          printf("Exiting program");
  
          return EXIT_FAILURE;
      }
  
     memset(&amp;buffer, 0, sizeof(buffer));
  
  
  n = recv(socketDescriptor, buffer, 255, 0);
  
   if(n&lt;0){
      perror("recv() failed");
      printf("Exiting program");
      printf("\n%s\n", buffer);
      return EXIT_FAILURE;                    //exit program if recv() fails
  }
  else{
      check = checkPlus(buffer);  //+ check for positive answer
      if (check==false){
          perror("failure");
  
          return EXIT_FAILURE;                //exit program if negative answer
      }
  }   
  printf("%s",buffer);
  
  return EXIT_SUCCESS;
  
  }
  </code></pre>
  
  <p>The connection is already established in another file.</p>
  
  <p>Here's an example for positive Answers.</p>
  
  <pre><code>Server: + MNM Gameserver &lt;&lt;GameserverVersion&gt;&gt; accepting connections
  Client: VERSION &lt;&lt;Client Version&gt;&gt;
  Server: + Client version accepted - please send GameID to join
  Client: ID &lt;&lt;ID&gt;&gt;
  Server: + Playing
  </code></pre>
  
  <p>When something is wrong, server replies with "-".</p>
  
  <p>so but i get this:</p>
  
  <pre><code>+MNM Gameserver v1.0 accepting connections
  
  Gameversion: 255, VERSION 1.1
  
  +Client version accepted - please send Game-ID to join
  
  ID K.GcY_EqHAs
  
  recv() failed: Connection reset by peer
  Exiting program
  </code></pre>
  
  <p>Please, anyone help me, I have no ideas...</p>
  
  <p>LG
  Max</p>