02. februar 2004 - 13:11Der er
4 kommentarer og 1 løsning
C klient server program
Hej, jeg skriver fordi jeg håbede på at der var nogen som lå inde med et realativt simpelt program, som kan sende f.eks. en besked eller en værdi og få et svar tilbage...Kan nogen hjælpe mig med en kode der kan det?
/* The server is also responsible for tidying up if it ever exits. When the server ends, we set our file scope variables to illegal values. This will catch any bugs if the server attempts to send messages after it has called server_ending. */
/* The server read function reads a message of any type (that is, from any client) from the queue, and returns the data part (ignoring the type) of the message. */
/* When the client starts, it needs to find the server and client queue identifiers. The client doesn't create the queues. This function will fail if the server isn't running, as the message queues won't exist. */
int client_starting() { #if DEBUG_TRACE printf("%d :- client_starting\n", getpid()); #endif
serv_qid = msgget((key_t)SERVER_MQUEUE, 0666); if (serv_qid == -1) return(0);
/* As with the server, when the client ends, we set our file scope variables to illegal values. This will catch any bugs where the client attempts to send messages after it has called client_ending. */
/* To send a message to the server, we store the data inside our structure. Notice that we must set the message key. As 0 is an illegal value for the key, leaving the key undefined would mean that it takes an (apparently) random value, so this function could occasionally fail if the value happens to be 0. */
/* When the client retrieves a message from the server, it uses its process ID to receive only messages addressed to itself, ignoring any messages for other clients. */
/* To retain complete compatibility with pipe_imp.c, we need to define an extra four functions. In our new program, however, the functions are empty. The operations they implemented when using pipes are simply not needed any more. */
int start_resp_to_client(const message_db_t mess_to_send) { return(1); }
da jeg selv har fundet svaret trækker jeg mine point tilbage
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.