PDA

View Full Version : [C/C++] client irc


jangy22xx
07-02-2010, 17:14
ciao ragazzi ho fatto in c il seguente programma che permette di connettersi a un server irc.
il problema è che dopo un tot di tempo m va in loop e il server mi manda il messaggio ping timeout ecc.... da cosa può dipendere?
posto il codice

#include <stdio.h>
#include <winsock.h>

int main(int argc, char *argv[])
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
return 0;

SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (hSocket == INVALID_SOCKET)
{
WSACleanup();
return 0;
}

SOCKADDR_IN sockAddr;
sockAddr.sin_port = htons(6667);
sockAddr.sin_addr.s_addr = inet_addr("69.42.221.149");
sockAddr.sin_family = AF_INET;

if (connect(hSocket, (SOCKADDR *)&sockAddr, sizeof(sockAddr)) != 0)
{
WSACleanup();
return 0;
}

char buffer[260], temp[260];

while (1)
{
int bytesRcv = recv(hSocket, buffer, sizeof(buffer), 0);

if (bytesRcv != 0 || bytesRcv != SOCKET_ERROR)
{
printf("%s", buffer);

if (strstr(buffer, "No ident response") != NULL)
{
sprintf(temp, "USER something something something :redguard \r\n");
send(hSocket, temp, strlen(temp), 0);

sprintf(temp, "NICK angy444 \r\n");
send(hSocket, temp, strlen(temp), 0);

sprintf(temp, "WHOIS angy444 \r\n");
send(hSocket, temp, strlen(temp), 0);

sprintf(temp, "JOIN #area.irc \r\n");
send(hSocket, temp, strlen(temp), 0);

}
} else break;
}

return 0;

jangy22xx
08-02-2010, 14:13
chiedere info su sto forum è inutile tanto nn ce mai nessuno che risponde....qua si può solo chiedere come accendere un computer allora si che ti rispondono in 234 perchè tutti lo sanno.....ma mi chiedo cosa stanno a fare le sezioni programmazione se poi la maggior parte dei topic sono senza risposte o con risposte non d'aiuto.
chiudo.

CwNd
08-02-2010, 14:54
Se non altro hai dimostrato di essere uno che non merita nessuna risposta.

jangy22xx
08-02-2010, 17:32
Se non altro hai dimostrato di essere uno che non merita nessuna risposta.

hahah perchè secondo te l'avrei ricevuta? vedi di stare zitto va