Client Server Tickets

Client Server Tickets

Systems Programming

PROGRAM DESCRIPTION:

In this assignment, you will write two complete C programs to support a client/server
model using Linux sockets for a ticket system. Your program will develop a two-tiered
ticketing system that will consist of a ticket outlet (i.e., the server) that will provide
services to “BUY” and “RETURN” tickets to two local ticket distributors (i.e., the clients)
as follows:

Server
o The server will generate N tickets, where N = 20, and each ticket will be
a randomly generated (and unique) 5-digit number. In this case, the server
will therefore maintain a database of 20 tickets (i.e., unique 5-digit
integers).
oWhen asked for a ticket using the “BUY” request, the server will look at its
database to see if any tickets are available. If there are available tickets,
the server will return the unique 5-digit ticket number to the client. If no
tickets remain, the server will return a “FULL” response and reject the
request. The server must remain connected and available, however, to
accept additional requests as clients may return tickets using the
“RETURN” request so that tickets become available to “BUY”.
oWhen a client returns a ticket using the “RETURN” request, the server will
“place” it back into the ticket pool, hopefully to be used later when another
“BUY” request comes in from a client. There may be cases, however,
when a client attempts to return an invalid ticket. In this case, the server
should return a “NOTEXIST” response and reject this “RETURN” request.
oFor any request other than “BUY” or “RETURN”, the server should return
an “INVALID” response and reject the request.
oThe server should provide an initial and final list of tickets with their status
before both clients are connected and after both clients are disconnected,
respectively. Additionally, the server should print any requests it receives
and the various statuses that occur during the execution of the program.
oWhen no clients remain “connected” to the server, the server will complete
its operations and shut down.

• Clients
o The client will request a ticket from the server using the “BUY” request.

oThe client may also, from time to time, return a ticket to the server using
the “RETURN” request. The client should provide the ticket number that is
being returned in this request.
oEach client will make 20 requests to the server, where approximately 75%
of the requests should be to “BUY” a ticket and 25% of the requests
should be to “RETURN” a ticket using a random number generator. If the
client has no tickets, but chooses to “RETURN” a ticket, your client code
should create an invalid ticket and attempt to return it to the server. When all of the client
requests have been processed, the client will disconnect from the server.
This process should be automated and executed within the code.
Your program should run on the INET domain using SOCK_STREAM (i.e., TCP)
sockets so that the server and each of the two clients execute on three different CSE
machines at the same time.
Given the randomness of the requests, it could be that not all of the client requests will
be met, so you will need to make sure you are able to handle error cases, such as a
client trying to return an invalid ticket or the server running out of tickets. 

nov01Bcli.c 

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <netdb.h>

void error(const char *msg)

{

perror(msg);

exit(0);

}

int main(intargc, char *argv[])

{

intsockfd, portno, n;

structsockaddr_inserv_addr;

structhostent *server;

char buffer[256];

if (argc< 3)

{

fprintf(stderr,”usage %s hostname port\n”, argv[0]);

exit(0);

}

portno = atoi(argv[2]);

sockfd = socket(AF_INET, SOCK_STREAM, 0);

if (sockfd< 0)

{

error(“ERROR opening socket”);

}

server = gethostbyname(argv[1]);

if (server == NULL)

{

fprintf(stderr,”ERROR, no such host\n”);

exit(0);

}

bzero((char *) &serv_addr, sizeof(serv_addr));

serv_addr.sin_family = AF_INET;

bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);

serv_addr.sin_port = htons(portno);

if (connect(sockfd,(structsockaddr *) &serv_addr,sizeof(serv_addr)) < 0)

{

error(“ERROR connecting”);

}

printf(“Please enter the message: “);

bzero(buffer,256);

fgets(buffer,255,stdin);

n = write(sockfd,buffer,strlen(buffer));

if (n < 0)

{

error(“ERROR writing to socket”);

}

bzero(buffer,256);

n = read(sockfd,buffer,255);

if (n < 0)

{

error(“ERROR reading from socket”);

}

printf(“%s\n”,buffer);

close(sockfd);

return 0;

} 

nov01Bsvr.c 

/* A simple server in the internet domain using TCP

The port number is passed as an argument */

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <netinet/in.h>

void error(const char *msg)

{

perror(msg);

exit(1);

}

int main(intargc, char *argv[])

{

intsockfd, newsockfd, portno;

socklen_tclilen;

char buffer[256];

structsockaddr_inserv_addr, cli_addr;

int n;

if (argc< 2)

{

fprintf(stderr,”ERROR, no port provided\n”);

exit(1);

}

sockfd = socket(AF_INET, SOCK_STREAM, 0);

if (sockfd< 0)

{

error(“ERROR opening socket”);

}

bzero((char *) &serv_addr, sizeof(serv_addr));

portno = atoi(argv[1]);

serv_addr.sin_family = AF_INET;

serv_addr.sin_addr.s_addr = INADDR_ANY;

serv_addr.sin_port = htons(portno);

if (bind(sockfd, (structsockaddr *) &serv_addr, sizeof(serv_addr)) < 0)

{

error(“ERROR on binding”);

}

listen(sockfd,5);

clilen = sizeof(cli_addr);

newsockfd = accept(sockfd, (structsockaddr *) &cli_addr, &clilen);

if (newsockfd< 0)

{

error(“ERROR on accept”);

}

bzero(buffer,256);

n = read(newsockfd,buffer,255);

if (n < 0)

{

error(“ERROR reading from socket”);

}

printf(“Here is the message: %s\n”,buffer);

n = write(newsockfd,”I got your message”,18);

if (n < 0)

{

error(“ERROR writing to socket”);

}

close(newsockfd);

close(sockfd);

return 0;

} 

nov03Acli.c 

#include <stdio.h>

#include <stdlib.h>

#include <sys/socket.h>

#include <sys/types.h>

#include <string.h>

#include <arpa/inet.h>   /* inet(3) functions */

#define MAXLINE 4096

voiddg_cli(FILE *fp, intsockfd, conststructsockaddr *pservaddr, socklen_tservlen);

int main(intargc, char **argv)

{

intsockfd;

structsockaddr_inservaddr;

if (argc != 2)

{

printf(“usage : %s <IP Address>\n”, argv[0]);

exit(1);

}

bzero(&servaddr, sizeof(servaddr));

servaddr.sin_family = AF_INET;

servaddr.sin_port = htons(9877);

inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

sockfd = socket(AF_INET, SOCK_DGRAM, 0);

dg_cli(stdin, sockfd, (structsockaddr *) &servaddr, sizeof(servaddr));

exit(0);

}

voiddg_cli(FILE *fp, intsockfd, conststructsockaddr *pservaddr, socklen_tservlen)

{

int n;

charsendline[MAXLINE], recvline[MAXLINE+1];

while (fgets(sendline, MAXLINE, fp) != NULL)

{

sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);

n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);

recvline[n] = ‘\0’;    /* null terminate */

printf(“rcvd msg from server: “);

fputs(recvline, stdout);

}

} 

nov03Asvr.c 

#include <stdio.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <string.h>

#include <arpa/inet.h>   /* inet(3) functions */

#define MAXLINE 4096

voiddg_echo(intsockfd, structsockaddr *pcliaddr, socklen_tclilen);

int main(intargc, char **argv)

{

intsockfd;

structsockaddr_inservaddr,cliaddr;

sockfd = socket(AF_INET, SOCK_DGRAM, 0);

bzero(&servaddr, sizeof(servaddr));

servaddr.sin_family = AF_INET;

servaddr.sin_addr.s_addr = htonl(INADDR_ANY);

servaddr.sin_port = htons(9877);

bind(sockfd, (structsockaddr *) &servaddr, sizeof(servaddr));

dg_echo(sockfd, (structsockaddr *) &cliaddr, sizeof(cliaddr));

}

voiddg_echo(intsockfd, structsockaddr *pcliaddr, socklen_tclilen)

{

int n;

socklen_tlen;

charmesg[MAXLINE];

for( ; ; )

{

len = clilen;

n = recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len);

printf(“rcvd from client: %s\n”, mesg);

sendto(sockfd, mesg, n, 0, pcliaddr, len);

}

} 

nov03Bcli.c 

#include <sys/types.h>

#include <sys/socket.h>

#include <string.h>

#include <sys/un.h>

#include <sys/time.h>

#include <fcntl.h>

#include <stdlib.h>

#define SOCKETNAME  “selectServerSocket”

int

main(void)

{

int s;          /* This end of connection*/

intlen;        /* length of sockaddr */

intnread;      /* return from read() */

intnready;     /* # fd’s ready. */

intmaxfd;      /* fd’s 0 to maxfd-1 checked. */

charbuf[1024];

fd_setfds;     /* set of file descriptors to check. */

structsockaddr_un name;

if( (s = socket(AF_UNIX, SOCK_STREAM, 0) ) < 0)

{

perror(“socket”);

exit(1);

}

/*Create the address of the server.*/

memset(&name, 0, sizeof(structsockaddr_un));

name.sun_family = AF_UNIX;

strcpy(name.sun_path, SOCKETNAME);

len = sizeof(name.sun_family) + strlen(name.sun_path);

/*Connect to the server.*/

if (connect(s, (structsockaddr *) &name, len) < 0)

{

perror(“connect”);

exit(1);

}

maxfd = s + 1;

while(1)

{

/* Set up polling. */

FD_ZERO(&fds);

FD_SET(s,&fds);

FD_SET(0,&fds);

/* Wait for some input. */

nready = select(maxfd, &fds, (fd_set *) 0, (fd_set *) 0,

(structtimeval *) 0);

/* If either device has some input,

read it and copy it to the other. */

if( FD_ISSET(s, &fds))

{

nread = recv(s, buf, sizeof(buf), 0);

/* If error or eof, terminate. */

if(nread< 1)

{

close(s);

exit(0);

}

write(1, buf, nread);

}

if( FD_ISSET(0, &fds))

{

nread = read(0, buf, sizeof(buf));

/* If error or eof, terminate. */

if(nread< 1){

close(s);

exit(0);

}

send( s, buf, nread, 0);

}

}

} 

nov03Bsvr.c 

/* This program sets up a socket to allow two clients to talk to each other */

#include <stdio.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <sys/un.h>

#include <string.h>

#include <stdlib.h>

#include <sys/time.h>

#define SOCKETNAME  “selectServerSocket”

int

main(void)

{

charbuf[1024];                  /* Buffer for messages to others. */

int s;                          /* Listen socket */

int ns;                         /* Socket for first connection. */

int ns2;                        /* Socket for second connection. */

intlen;                        /* len of sockaddr */

intmaxfd;                      /* descriptors up to maxfd-1 polled*/

intnread;                      /* # chars on read()*/

intnready;                     /* # descriptors ready. */

structsockaddr_un name;

fd_setfds;                     /* Set of file descriptors to poll*/

/* Remove any previous socket.*/

unlink(SOCKETNAME);

/* Create the socket. */

if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)

{

perror(“socket”);

exit(1);

}

/* Create the address of the server.*/

memset(&name, 0, sizeof(structsockaddr_un));

name.sun_family = AF_UNIX;

strcpy(name.sun_path, SOCKETNAME);

len = sizeof(name.sun_family) + strlen(name.sun_path);

/*Bind the socket to the address.*/

if (bind(s, (structsockaddr *) &name, len) < 0)

{

perror(“bind”);

exit(1);

}

/* Listen for connections. */

if (listen(s, 5) < 0)

{

perror( “listen”);

exit(1);

}

/*Accept a connection.*/

if ((ns = accept(s, (structsockaddr *) &name, &len)) < 0)

{

perror(“accept”);

exit(1);

}

/* Accept another connection. */

if ((ns2 = accept(s, (structsockaddr *) &name, &len)) < 0)

{

perror(“accept”);

exit(1);

}

maxfd = (ns > ns2 ? ns : ns2) + 1;

while (1)

{

/* Set up polling using select. */

FD_ZERO(&fds);

FD_SET(ns,&fds);

FD_SET(ns2,&fds);

/* Wait for some input. */

nready = select(maxfd, &fds, (fd_set *) 0, (fd_set *) 0,

(structtimeval *) 0);

/* If either descriptor has some input,

read it and copy it to the other. */

if( FD_ISSET(ns, &fds))

{

nread = recv(ns, buf, sizeof(buf), 0);

/* If error or eof, terminate. */

if(nread< 1)

{

close(ns);

close(ns2);

exit(0);

}

send( ns2, buf, nread, 0);

}

if( FD_ISSET(ns2, &fds))

{

nread = recv(ns2, buf, sizeof(buf), 0);

/* If error or eof, terminate. */

if(nread< 1)

{

close(ns);

close(ns2);

exit(0);

}

send( ns, buf, nread, 0);

}

}

} 

oct30Acli.c 

#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

#include <string.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <sys/un.h>

#define SOCK_PATH “my_socket”

int main(void)

{

int s, t, len;

structsockaddr_un remote;

charstr[100];

if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)

{

perror(“socket”);

exit(1);

}

printf(“Trying to connect…\n”);

remote.sun_family = AF_UNIX;

strcpy(remote.sun_path, SOCK_PATH);

len = strlen(remote.sun_path) + sizeof(remote.sun_family);

if (connect(s, (structsockaddr *)&remote, len) == -1)

{

perror(“connect”);

exit(1);

}

printf(“Connected.\n”);

while(printf(“> “), fgets(str, 100, stdin), !feof(stdin))

{

if (send(s, str, strlen(str), 0) == -1)

{

perror(“send”);

exit(1);

}

if ((t=recv(s, str, 100, 0)) > 0)

{

str[t] = ‘\0’;

printf(“echo> %s”, str);

}

else

{

if (t < 0)

{

perror(“recv”);

}

else

{

printf(“Server closed connection\n”);

}

exit(1);

}

}

close(s);

return 0;

} 

oct30Asvr.c 

#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

#include <string.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <sys/un.h>

#define SOCK_PATH “my_socket”

int main(void)

{

int s, s2, t, len;

structsockaddr_un local, remote;

charstr[100];

if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)

{

perror(“socket”);

exit(1);

}

local.sun_family = AF_UNIX;

strcpy(local.sun_path, SOCK_PATH);

unlink(local.sun_path); // remove existing socket

len = strlen(local.sun_path) + sizeof(local.sun_family);

if (bind(s, (structsockaddr *)&local, len) == -1)

{

perror(“bind”);

exit(1);

}

if (listen(s, 5) == -1)

{

perror(“listen”);

exit(1);

}

for(;;)

{

int done, n;

printf(“Waiting for a connection…\n”);

t = sizeof(remote);

if ((s2 = accept(s, (structsockaddr *)&remote, &t)) == -1)

{

perror(“accept”);

exit(1);

}

printf(“Connected.\n”);

done = 0;

do

{

n = recv(s2, str, 100, 0);

if (n > 0)

{

str[n] = ‘\0’;

printf(“Received :  %s\n”, str);

}

else if (n <= 0)

{

if (n < 0) perror(“recv”);

done = 1;

}

if (!done)

{

if (send(s2, str, n, 0) < 0)

{

perror(“send”);

done = 1;

}

}

} while (!done);

close(s2);

}

close(s);

return 0;

} 

Solution 

minor6cli.c 

#include <unistd.h>

#include <sys/socket.h>

#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

#include <sys/types.h>

#include <string.h>

#include <netinet/in.h>

#include <time.h>

#include <netdb.h>

#define N 20  /* maxim number of tickets in the database */

/* execute a random command from the client,

* count saves the number of tickets in the array */

voidrandom_command(intsockfd, int tickets[N], int *count);

int main(intargc, char *argv[])

{

intsockfd, portno;

structsockaddr_inaddr;

structhostent *server;

int i;

/* to save the tickets bought from the server. */

int tickets[N];

int count = 0;

/* get the hostname and port of the server from

* the arguments. */

if (argc != 3)

{

printf(“Usage: %s hostname port\n”, argv[0]);

exit(-1);

}

portno = atoi(argv[2]);

/* create the socket */

sockfd = socket(AF_INET, SOCK_STREAM, 0);

if (sockfd< 0)

{

fprintf(stderr, “ERROR opening socket\n”);

exit(errno);

}

/* get the server’s ip address information */

server = gethostbyname(argv[1]);

if (server == NULL)

{

fprintf(stderr, “ERROR, no such host\n”);

exit(errno);

}

/* connect with the server. */

bzero((char *) &addr, sizeof(addr));

addr.sin_family = AF_INET;

bcopy((char *)server->h_addr, (char *)&addr.sin_addr.s_addr, server->h_length);

addr.sin_port = htons(portno);

if (connect(sockfd,(structsockaddr *) &addr, sizeof(addr)) < 0)

{

fprintf(stderr, “ERROR connecting\n”);

exit(errno);

}

/* automatically make 20 requests to the server,

* 75% of which are BUY and 25% are RETURN.*/

srand(time(NULL));

for (i = 0; i < 20; i++)

{

random_command(sockfd, tickets, &count);

}

close(sockfd);

return 0;

}

voidrandom_command(intsockfd, int tickets[N], int *count)

{

int ticket, i;

ssize_tnread;

charbuf[1024];

if (rand() % 4 == 0) /* 25% to return a ticket */

{

if (*count > 0)

{

/* return the earliest ticket in the array */

ticket = tickets[0];

*count = *count – 1;

for (i = 0; i < *count; i++)

{

tickets[i] = tickets[i + 1];

}

}

else

{

/* return a random ticket to return */

ticket = rand() % 90000 + 10000;

}

snprintf(buf, sizeof(buf), “RETURN %d”, ticket);

}

else

{

/* otherwise buy a ticket */

strcpy(buf, “BUY”);

}

/* send the command to the server and handle the feed back */

if (send(sockfd, buf, strlen(buf) + 1, 0) > 0)

{

if ((nread = recv(sockfd, buf, sizeof(buf), 0)) > 0)

{

/* if the returned value is a ticket, then

* this must be a buy command from the server. */

ticket = atoi(buf);

if (ticket > 0)

{

tickets[*count] = ticket;

*count = *count + 1;

}

}

}

} 

minor6svr.c 

#include <unistd.h>

#include <sys/socket.h>

#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

#include <sys/types.h>

#include <string.h>

#include <netinet/in.h>

#include <time.h>

#define N 20  /* number of tickets in the database */

#define M 2   /* number of allowed clients */

intcreate_server(int port);          /* create a server socket at the given port */

voidcreate_database(int database[]); /* positive means the ticket is available */

voidprint_database(int database[]);  /* print the tickets in the database. */

int react(int database[], intcs[]); /* handle the request of the clients */

/* handle the command issued by the the client. If

* the client has disconnected, return 0. */

int handle(intidx, intfd, char command[], int database[]);

int main(intargc, char *argv[])

{

intsockfd, portno;

int database[N];

intcs[M];        /* socket fd for clients */

int i;

if (argc != 2)

{

printf(“Usage: %s port\n”, argv[0]);

exit(-1);

}

/* create a server socket at the specified port. */

portno = atoi(argv[1]);

sockfd = create_server(portno);

/* create and display the database */

create_database(database);

print_database(database);

/* accept the collections of two clients before handling the clients */

for (i = 0; i < M; i++)

{

structsockaddr_inaddr;

socklen_tlen = sizeof(addr);

if ((cs[i] = accept(sockfd, (structsockaddr *)&addr, &len)) < 0)

{

printf(“ERROR could not accept client\n”);

exit(errno);

}

}

/* react function returns 0 when all clients have disconnected. */

while (react(database, cs));

/* print the database before close the program */

print_database(database);

close(sockfd);

return 0;

}

voidcreate_database(int database[])

{

int i;

/* each ticket is a random five digit number. */

srand(time(NULL));

for (i = 0; i < N; i++)

{

int ticket = rand() % 90000 + 10000;

database[i] = ticket;

}

}

voidprint_database(int database[])

{

int i;

printf(“[SERVER]: Database Table:\n”);

printf(“————————-\n”);

/* if a ticket has a negative number, the ticket is sold. */

for (i = 0; i < N; i++)

{

if (database[i] > 0)

{

printf(“[Tkt# %2d] %5d : AVAIL\n”, i, database[i]);

}

else

{

printf(“[Tkt# %2d] %5d : SOLD\n”, i, -database[i]);

}

}

printf(“————————-\n”);

}

intcreate_server(intportno)

{

intsockfd;

structsockaddr_inaddr;

int yes = 1;

/* create the socket */

sockfd = socket(AF_INET, SOCK_STREAM, 0);

if (sockfd< 0)

{

printf(“ERROR opening socket\n”);

exit(errno);

}

/* make the address reusable so we can restart the

* server right after it’s closed. */

setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));

bzero((char *) &addr, sizeof(addr));

addr.sin_family = AF_INET;

addr.sin_addr.s_addr = INADDR_ANY;

addr.sin_port = htons(portno);

/* bind and listen on the specified port */

if (bind(sockfd, (structsockaddr *) &addr, sizeof(addr)) < 0)

{

printf(“ERROR on binding\n”);

exit(errno);

}

if (listen(sockfd, 5) < 0)

{

printf(“ERROR on listening\n”);

exit(errno);

}

returnsockfd;

}

int react(int database[], intcs[])

{

int i;

intmaxfd = 0;

fd_setfds;

charbuf[1024];

ssize_tnread;

/* add the client socket fd to the select set. */

FD_ZERO(&fds);

for (i = 0; i < M; i++)

{

if (cs[i] > 0)

{

FD_SET(cs[i], &fds);

if (cs[i] >maxfd)

{

maxfd = cs[i];

}

}

}

/* clients have all disconnected. */

if (maxfd == 0)

{

return 0;

}

/* wait for the input from clients */

select(maxfd + 1, &fds, NULL, NULL, NULL);

for (i = 0; i < M; i++)

{

if (cs[i] > 0 && FD_ISSET(cs[i], &fds))

{

/* read the command from the client */

nread = recv(cs[i], buf, sizeof(buf), 0);

if (nread<= 0 || handle(i + 1, cs[i], buf, database) == 0)

{

/* this client has closed its connection */

close(cs[i]);

cs[i] = 0;

}

}

}

return 1;

}

int handle(intidx, intfd, char command[], int database[])

{

int i;

charbuf[1024];

printf(“[CLIENT %d]: %s\n”, idx, command);

/* check the type of the command and handle accordingly. */

if (strcmp(command, “BUY”) == 0)

{

int found = -1;

/* try to find an available ticket to send to the client */

for (i = 0; i < N; i++)

{

if (database[i] > 0)

{

found = i;

break;

}

}

if (found >= 0)

{

/* construct the feedback for the client */

printf(“[SERVER X]: Client %d BUY %d\n”, idx, database[found]);

snprintf(buf, sizeof(buf), “%d”, database[found]);

database[found] = -database[found];

}

else

{

/* no ticket is available, send FULL */

printf(“[SERVER X]: Database full\n”);

strcpy(buf, “FULL”);

}

}

/* the client tries to return a ticket */

else if (strncmp(command, “RETURN “, 7) == 0)

{

int found = -1;

int ticket = atoi(&command[7]);

/* make sure the ticket was sold */

for (i = 0; i < N; i++)

{

if (database[i] < 0 && ticket == -database[i])

{

found = i;

break;

}

}

/* construct the return feedback to the client */

if (found >= 0)

{

database[found] = -database[found];

printf(“[SERVER X]: Client %d RETURN %d\n”, idx, database[found]);

strcpy(buf, “EXIST”);

}

else

{

printf(“[SERVER X]: Client %d RETURN %d [NOTEXIST]\n”, idx, ticket);

strcpy(buf, “NOTEXIST”);

}

}

else

{

strcpy(buf, “INVALID”);

}

/* send the feedback to the client */

return send(fd, buf, strlen(buf) + 1, 0) != -1;

}