Mi sto esercitando con la programmazione basilare in c delle socket. Qui di seguito un programmino client/server che si scambiano stringhe ed elaborazioni (il server riceve una stringa da cui rimuove le vocali e la rispedisce al client). Dopo varie correzioni il programma sembra funzionare, la mia domanda ora è:
1)se volessi continuare con l'invio e la ricezione di altre stringhe, utilizzo buffer diversi o pulisco quelli usati per riutilizzarli? Se sì, come?
2)in entrambi i casi le funzioni send() e recv() si possono utilizzare in sequenza senza particolari problemi?
1)se volessi continuare con l'invio e la ricezione di altre stringhe, utilizzo buffer diversi o pulisco quelli usati per riutilizzarli? Se sì, come?
2)in entrambi i casi le funzioni send() e recv() si possono utilizzare in sequenza senza particolari problemi?
Codice:
***SERVER***
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] defined WIN32[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<winsock2.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]
[/COLOR][/SIZE][/COLOR][/SIZE]
[B]
[SIZE=2][COLOR=#7f0055]
[SIZE=2][COLOR=#7f0055]
#else
[/COLOR][/SIZE]
[/COLOR][/SIZE]
[/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#define[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] closesocket close[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<sys/socket.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<arpa/inet.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<unistd.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]
[/COLOR][/SIZE][/COLOR][/SIZE]
[B]
[SIZE=2][COLOR=#7f0055]
[SIZE=2][COLOR=#7f0055]
#endif
[/COLOR][/SIZE]
[/COLOR][/SIZE]
[/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<stdio.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<stdlib.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<string.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#define[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] BUFSIZE 30[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [B]ClearWinSock[/B]() {[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] defined WIN32[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]WSACleanup[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]();[/SIZE]
[SIZE=2]
[/SIZE]
[B]
[SIZE=2][COLOR=#7f0055]
[SIZE=2][COLOR=#7f0055]
#endif
[/COLOR][/SIZE]
[/COLOR][/SIZE]
[/B][SIZE=2]}
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [B]main[/B]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]) {[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//---------------------------INIZIALIZZAZIONE WSADATA
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] defined WIN32[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]WSADATA[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] wsaData;[/SIZE]
[SIZE=2]
[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] iResult = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]WSAStartup[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](MAKEWORD(2,2), &wsaData);[/SIZE]
[SIZE=2]
[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (iResult != 0) {[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Error at WSAStartup"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]#endif
[/COLOR][/SIZE]
[/COLOR][/SIZE]
[/B][SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//-------------------------------CREAZIONE SOCKET
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Mysocket;[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] Mysocket = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]socket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](PF_INET, SOCK_STREAM, IPPROTO_TCP);[/SIZE]
[SIZE=2]
[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Mysocket < 0) {[/SIZE]
[SIZE=2]
[/SIZE]
[B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"socket creation failed\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]struct[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]sockaddr_in[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sad;[/SIZE]
[SIZE=2]
[/SIZE]
[B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]memset[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](&sad, 0, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](sad));[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] sad.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]sin_family[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = AF_INET;[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] sad.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]sin_addr[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].s_addr = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]inet_addr[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"127.0.0.1"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] sad.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]sin_port[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]htons[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (9888);[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//------------------------ASSEGNAZIONE PORTA E IP ALLA SOCKET
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]bind[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Mysocket, ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]struct[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]sockaddr[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]*) &sad, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](sad)) <0) {[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"bind() failed\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]closesocket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Mysocket);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//---------------------------SETTAGGIO SOCKET ALL'ASCOLTO
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] qlen = 10;[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]listen[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Mysocket, qlen) < 0) {[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"listen() failed\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]closesocket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Mysocket);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]struct[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]sockaddr_in[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] cad;[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Csocket;[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] clientlen;[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//------------------------------ACCETTA LA CONNESSIONE
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]while[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (1) {[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"In [U]attesa[/U] [U]di[/U] [U]un[/U] client [U]con[/U] [U]cui[/U] [U]comunicare[/U]\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]memset[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](&cad, 0, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](cad));[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] clientlen = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](cad);[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]((Csocket = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]accept[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Mysocket, ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]struct[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]sockaddr[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]*) &cad, &clientlen)) < 0) {[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"accept failed\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]closesocket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Mysocket);[/SIZE]
[SIZE=2]
ClearWinSock();
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"[U]connesso[/U] [U]con[/U] [U]il[/U] client\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//---------------------------------------INVIO STRINGA AL CLIENT
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]char[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]* inputString = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"[U]connessione[/U] [U]avvenuta[/U]"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] stringlen = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]strlen[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](inputString);[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]send[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Csocket, inputString, stringlen, 0) != stringlen) {[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"client-send() sent a different number of bytes than expected"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]closesocket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Csocket);[/SIZE]
[SIZE=2]
ClearWinSock();
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]system[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"pause"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//-------------------------------------RICEZIONE STRINGA DAL CLIENT
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]char[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] str1[BUFSIZE]; [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]char[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] str1des[BUFSIZE];[/SIZE]
[SIZE=2]
[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] i,j=0;[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[U]recv[/U] ([U]Csocket[/U], str1, BUFSIZE - 1, 0);[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] read = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]recv[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Csocket, str1, BUFSIZE-1, 0); str1[read] = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'\0'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//-------------------------------ELIMINAZIONE VOCALI DALLA STRINGA RICEVUTA
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]for[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](i=0;i<=[/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]strlen[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](str1)+1;i++) {[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'a'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]||str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'e'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]||str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'i'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]||str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'o'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]||str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'u'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ||str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'A'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]||str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'E'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]||str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'I'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]||str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'O'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]||str1[i]==[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'U'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] str1[i]=[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]' '[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/COLOR][/SIZE][/COLOR][/SIZE][/B]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE][/B]
[SIZE=2]
str1des[j++]=str1[i];
}
[/SIZE][SIZE=2] str1des[j]=[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'\0'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//-----------------------------------INVIO STRINGA ELABORATA AL CLIENT
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]send[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Csocket, str1des, [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]strlen[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](str1des), 0) != [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]strlen[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](str1des)) {[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"client-send() sent a different number of bytes than expected"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]closesocket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Csocket);[/SIZE]
[SIZE=2]
ClearWinSock();
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]system[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"pause"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//------------------------------------------CHIUSURA CONNESSIONE
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880][B]closesocket[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (Csocket);[/SIZE]
[SIZE=2]
ClearWinSock();
[/SIZE][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880][B]printf[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880][B]system[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"pause"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]return[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
***CLIENT***
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] defined WIN32[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<winsock2.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]
[/COLOR][/SIZE][/COLOR][/SIZE]
[B]
[SIZE=2][COLOR=#7f0055]
[SIZE=2][COLOR=#7f0055]
#else
[/COLOR][/SIZE]
[/COLOR][/SIZE]
[/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#define[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] closesocket close[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<sys/socket.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<arpa/inet.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<unistd.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]
[/COLOR][/SIZE][/COLOR][/SIZE]
[B]
[SIZE=2][COLOR=#7f0055]
[SIZE=2][COLOR=#7f0055]
#endif
[/COLOR][/SIZE]
[/COLOR][/SIZE]
[/B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<stdio.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<stdlib.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]<string.h>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#define[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] BUFSIZE 30[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [B]ClearWinSock[/B]() {[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] defined WIN32[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]WSACleanup[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]();[/SIZE]
[SIZE=2]
[/SIZE]
[B]
[SIZE=2][COLOR=#7f0055]
[SIZE=2][COLOR=#7f0055]
#endif
[/COLOR][/SIZE]
[/COLOR][/SIZE]
[/B][SIZE=2]}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//-----------------------------INIZIALIZZAZIONE WSADATA
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [B]main[/B] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]) {[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]#if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] defined WIN32[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]WSADATA[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] wsaData;[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] iResult = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]WSAStartup[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (MAKEWORD (2,2), &wsaData);[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (iResult !=0) {[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"error at WSASturtup\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]#endif
[/COLOR][/SIZE]
[/COLOR][/SIZE]
[/B][SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//--------------------------------CREAZIONE SOCKET
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Csocket;[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] Csocket = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]socket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (PF_INET, SOCK_STREAM, IPPROTO_TCP);[/SIZE]
[SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Csocket < 0) {[/SIZE]
[SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"socket creation failed"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]closesocket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Csocket);[/SIZE]
[SIZE=2]
ClearWinSock();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//--------------------------COSTRUZIONE INDIRIZZO SERVER[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]struct[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]sockaddr_in[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sad;[/SIZE]
[SIZE=2]
[/SIZE]
[B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]memset[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (&sad, 0, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](sad));[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] sad.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]sin_family[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = AF_INET;[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] sad.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]sin_addr[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].s_addr = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]inet_addr[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"127.0.0.1"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] sad.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]sin_port[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]htons[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (9888);[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//------------------------------CONNESSIONE AL SERVER
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]connect[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Csocket, ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]struct[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]sockaddr[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]*) &sad, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](sad)) < 0) {[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"failed to connect\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]closesocket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Csocket);[/SIZE]
[SIZE=2]
ClearWinSock();
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//-----------------------------RICEZIONE DATI DAL SERVER
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]char[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] buf[BUFSIZE];[/SIZE]
[SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] read = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]recv[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Csocket, buf, BUFSIZE - 1, 0);[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (read <=0) {[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"[U]Qualcosa[/U] non [U]và[/U]!\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]else[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] buf[read] = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]'\0'[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Server [U]scrive[/U]: %s\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], buf);[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//----------------------------INVIO PRIMA STRINGA AL SERVER
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]char[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] str1[BUFSIZE]; [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] stringlen;[/SIZE]
[SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880][B]printf[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"[U]inserisci[/U] [U]prima[/U] [U]stringa[/U]:\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880][B]fgets[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (str1, BUFSIZE,stdin);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2]stringlen = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]strlen[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](str1);[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]send[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Csocket, str1, stringlen, 0) != stringlen) {[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"client-send() sent a different number of bytes than expected"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]closesocket[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](Csocket);[/SIZE]
[SIZE=2]
ClearWinSock();
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]system[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"pause"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
[/SIZE]
[SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//------------------------------RICEZIONE STRINGA ELABORATA DAL SERVER
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]char[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] buf2[BUFSIZE];[/SIZE]
[SIZE=2]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] read2 = [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]recv[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Csocket, buf2, BUFSIZE - 1, 0);[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (read2 <=0) {[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"[U]Qualcosa[/U] non [U]và[/U]!\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]else[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {[/SIZE]
[SIZE=2]
buf2[read2] = 0;
[/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Server [U]scrive[/U]: %s\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], buf2);[/SIZE]
[SIZE=2]
}
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//---------------------------------------CHIUSURA CONNESSIONE
[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880][B]closesocket[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (Csocket);[/SIZE]
[SIZE=2]
ClearWinSock();
[/SIZE][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880][B]printf[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880][B]system[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"pause"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][B]return[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 0;[/SIZE]
[SIZE=2]
}
[/SIZE]
[/SIZE]