Socket ( server client Get pid )

This is a discussion on Socket ( server client Get pid ) within the C Programming forums, part of the General Programming Boards category; hi guys now I want to change the server so that it is able to serve more customers simultaneously. as ...

  1. #1
    Syd
    Syd is offline
    Registered User
    Join Date
    Feb 2011
    Posts
    1

    Angry Socket ( server client Get pid )

    hi guys
    now I want to change the server so that it is able to serve more customers
    simultaneously. as there is a process "generic "
    initially creates the server and then creates the customer (at random intervals). Each
    client requests the server to process a string, and has been answered,
    ends. The creation of the customers that the process continues until the generator
    it receives a SIGINT signal (eg, keyboard). At which point the
    generator stops generating customers, when all customers have been completed,
    sends a SIGUSR1 signal to the server that runs it close. The
    communication between clients and servers must be made through a single socket.
    ....
    I wrote up here guys ... but I do not know as I continue ..
    please help me

    code server :
    Code:
    /* upperserver.c : un server per maiuscolare linee di testo */
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <ctype.h>
    
    #define SERVER_PORT 1313
    #define LINESIZE 80
    
    void
    upperlines (int in, int out)
    {
      char inputline[LINESIZE];
      int len, i;
    
      while ((len = recv (in, inputline, LINESIZE, 0)) > 0)
        {
    	    sleep(10);
          for (i = 0; i < len; i++)
    	inputline[i] = toupper (inputline[i]);
          send (out, inputline, len, 0);
        }
    }
    
    int
    main (unsigned argc, char **argv)
    {
      int sock, client_len, fd;
      struct sockaddr_in server, client;
    
      /* impostazione del transport end point */
      if ((sock = socket (AF_INET, SOCK_STREAM, 0)) == -1)
        {
          perror ("chiamata alla system call socket fallita");
          exit (1);
        }
    
      server.sin_family = AF_INET;
      server.sin_addr.s_addr = INADDR_ANY;
      server.sin_port = htons (SERVER_PORT);
    
      /* binding dell'indirizzo al transport end point */
      if (bind (sock, (struct sockaddr *) &server, sizeof server) == -1)
        {
          perror ("chiamata alla system call bind fallita");
          exit (2);
        }
    
      listen (sock, 1);
    
      /* gestione delle connessioni dei client */
      while (1)
        {
          client_len = sizeof (client);
          if ((fd = accept (sock, (struct sockaddr *) &client, &client_len)) < 0)
    	{
    	  perror ("accepting connection");
    	  exit (3);
    	}
          fprintf (stderr, "Aperta connessione.\n");
          send (fd, "Benvenuto all'UpperServer!\n", 27, 0);
          upperlines (fd, fd);
          close (fd);
          fprintf (stderr, "Chiusa connessione.\n");
        }
    }
    
    ********************************************************************************
    code client :
    
    #include   <stdio.h>
    #include   <stdlib.h>
    #include   <string.h>
    #include   <ctype.h>
    #include   <sys/types.h>
    #include   <sys/socket.h>
    #include   <netinet/in.h>
    
    #define MAXLENGTH 80
    #define SERVER_PORT 1313
    
    main ()
    {
      int sockfd;
      struct sockaddr_in server={AF_INET,htons(SERVER_PORT),INADDR_ANY};
      int i = 0, len;
      char buf[MAXLENGTH], c;
    
      if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
        {
          perror("chiamata alla system call socket fallita");
          exit(1);
        }
    
      /* connessione al server */
      if (connect(sockfd, (struct sockaddr *) &server, sizeof server) == -1)
        {
          perror("connessione al server fallita");
          exit(2);
        }
    
      /* ricezione e stampa a video del messaggio di benvenuto del server */
      if (recv(sockfd, buf, 27, 0) > 0)
        {
          printf("%s", buf);
        }
      else
        {
          perror("Connessione al server interrotta");
          exit(3);
        }
    
      /* acquisizione della stringa da standard input */
      printf("\nDigita una stringa:");
      while ((c = getchar()) != '\n' && i < MAXLENGTH)
        buf[i++] = c;
    
      buf[i] = '\0';
      len = strlen(buf);
    
      /* invio e ricezione della stringa */
      if (send(sockfd, buf, len, 0) == -1)
        {
          perror("Errore nell'invio della stringa al server");
          exit(4);
        }
    
      if (recv(sockfd, buf, len, 0) > 0)
        {
          printf("%s\n", buf);
        }
      else
        {
          perror("Connessione al server interrotta");
          exit(3);
        }
    
      /* chiusura della connessione */
      close(sockfd);
    }
    thank you for help!!
    Last edited by Syd; 02-15-2011 at 11:39 AM. Reason: HHHHHHHHelp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Leak in AppWizard-Generated Code
    By jrohde in forum Windows Programming
    Replies: 4
    Last Post: 05-19-2010, 05:24 PM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 05:02 PM
  3. Socket Programming Problem!!!!
    By bobthebullet990 in forum Networking/Device Communication
    Replies: 2
    Last Post: 02-21-2008, 07:36 PM
  4. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 08:04 PM
  5. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 12:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21