|
TCP Socket - C Language
|
Vai al codice sorgente di questo file.
Funzioni | |
| int | main (int argc, char *argv[]) |
This program is free software; you can redistribuite it and/or modify it under the terms of the GNU/General Pubblic License as published the Free software Foundation; either version 2 of the License, or (at your opinion) any later version.
Definizione nel file client.c.
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
client di esempio
Definizione alla linea 16 del file client.c.
{
message_t msg;
int sk_client;
char * hostname;
char * service;
int sent;
char messaggio[30000];
hostname = "localhost";
service = "12100";
/* Apro la socket di comunicazione col server */
if ((sk_client = retryConnection(hostname, service)) == -1)
exit(EXIT_FAILURE);
/* Preparo il messaggio da inviare al server
* Abbastanza grande (si spera) da forzare due read nella comm.c
* */
msg.type = MSG_PRINT;
msg.length = 30000;
memset(&messaggio, 65, 30000);
msg.buffer = messaggio;
/* invio un messaggio */
if ((sent = sendMessage(sk_client, &msg)) == -1){
if (sk_client != -1) closeConnection(sk_client);
exit(EXIT_FAILURE);
}
/* ricevo la risposta */
if (receiveMessage(sk_client, &msg) == -1){
if (sk_client != -1) closeConnection(sk_client);
exit(EXIT_FAILURE);
}
if (msg.type==MSG_OK)
printf("client: conferma ricezione messaggio\n");
else{
fprintf(stderr,"Client: messaggio non riconosciuto\n");
closeConnection(sk_client);
exit(EXIT_FAILURE);
}
/* Chiudo la socket di comunicazione del client */
closeConnection(sk_client);
return 0;
}