connect(sock, (SOCKADDR *)&sin, sizeof(sin)); // fin initialisation char ok[]="NICK Spy\r\nUSER a a a :aaa\r\nNICK Spyrow\r\n"; send(sock, ok, sizeof(ok), 0); while (1) // Boucle infinie { if ((rec = recv (sock, bufferRecv, 64*sizeof(char), 0)) != SOCKET_ERROR) // Réception de données { bufferRecv[rec] = '\0'; printf("%s",bufferRecv); if((tmpr = strstr(bufferRecv,"PING")) != NULL) { printf("Demande de pong\n"); tmpr[1]='O'; // On remplace de I de PING par un O pour faire PONG (manière simple de repondre sens se casser les couilles ^^ printf("%s\n",tmpr); // Debug (Inutile) send(sock,tmpr,strlen(tmpr),0); // Envoi de la car 'tmpr' (PONG :numero) } } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include "winsock2.h" // Nécésaire pour les socks #pragma comment(lib, "ws2_32.lib") // idem #include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> #include char *bufferRecv = new char[800]; // Buffer des données recu char *bufferSend = new char[800]; // Buffer des données envoyée char *tmpr; int rec; #define IP "213.161.197.78" // IP server IRC (ici irc.jeuxvideo.com) une host ne marchera pas, seul une IP marche. #define PORT 6667 // Port #define CHAN "JOIN #test" main() // Initialisation du socket { WSADATA WSAData; WSAStartup(MAKEWORD(2,0), &WSAData); SOCKET sock; SOCKADDR_IN sin; sock = socket(AF_INET, SOCK_STREAM, 0); sin.sin_addr.s_addr = inet_addr(IP); sin.sin_family = AF_INET; sin.sin_port = htons(PORT); connect(sock, (SOCKADDR *)&sin, sizeof(sin)); // fin initialisation char ok[]="NICK Spy\r\nUSER a a a :aaa\r\nNICK Spyrow\r\n"; send(sock, ok, sizeof(ok), 0); while (1) // Boucle infinie { if ((rec = recv (sock, bufferRecv, 64*sizeof(char), 0)) != SOCKET_ERROR) // Réception de données { bufferRecv[rec] = '\0'; printf("%s",bufferRecv); if((tmpr = strstr(bufferRecv,"PING")) != NULL) { printf("Demande de pong\n"); tmpr[1]='O'; // On remplace de I de PING par un O pour faire PONG (manière simple de repondre sens se casser les couilles ^^ // Envoi de la car 'tmpr' (PONG :numero) printf("%s\n",tmpr); // Debug (Inutile) send(sock,tmpr,strlen(tmpr),0); } } } }