Example #1
0
int main()
{
  client_make_connection();
  handle_messages();
  client_close_connection();
  return 0;
}
Example #2
0
/**
 * Traite la connection avec le client.
 */
void process_client()
{
  char buffer[MESSAGE_BUFFER_SIZE];
  char host[HOST_SIZE];
  
  /* Le client vient de se connecter */
  client_open_connection();
  
  if (gethostname(host, sizeof host) == -1 && errno == EINVAL)
    host[sizeof host - 1] = '\0';
  
  /* On envoie un message de bienvenue et le prompt */
  snprintf(buffer, sizeof buffer, "%s [ %s ]\n", welcome, host);
  send_basic(client_socket, buffer, strlen(buffer));
  send_basic(client_socket, prompt_client, strlen(prompt_client));
  
  /* On traite tous les messages du client */
  while (recv(client_socket, buffer, MESSAGE_BUFFER_SIZE, 0) > 0)
    {
      verbose("Client # %s\n", buffer);
      
      /* On traite la commande  */
      if (parse_client_line(client_socket, buffer) == MSG_QUIT)
	break;
      
      send_basic(client_socket, prompt_client, strlen(prompt_client));
    }
  
  /* Si on arrive ici, c'est que le client a quitté. */
  client_close_connection();
}
Example #3
0
int rpcc_close_connection (struct connection *c, int who) {
  if (RPCC_FUNC(c)->rpc_close != NULL) {
    RPCC_FUNC(c)->rpc_close (c, who);
  }

  return client_close_connection (c, who);
}
Example #4
0
File: client.c Project: hpc/Spindle
static void reset_server_connection()
{
   client_close_connection(ldcsid);

   ldcsid = -1;
   old_cwd[0] = '\0';

   init_server_connection();
}
Example #5
0
File: client.c Project: hpc/Spindle
int client_done()
{
   check_for_fork();
   if (ldcsid == -1 || !use_ldcs)
      return 0;

   debug_printf2("Done. Closing connection %d\n", ldcsid);
   send_end(ldcsid);
   client_close_connection(ldcsid);
   return 0;
}
Example #6
0
/**
 * Arrête le serveur proprement en déconnectant les clients et lui même.
 */
static void shutdown_server() {
  puts("Fermeture du démon ...");

  /* Fermeture du client */
  if (client_socket > 0)
    client_close_connection(client_socket);

  /* Fermeture du serveur */
  if (close(server_socket) == -1)
    {
      perror("Impossible de fermer le socket serveur");
      exit(EXIT_FAILURE);
    }
  
  exit(EXIT_SUCCESS);
}