Before I begin, let me analyze my thoughts and gather your minds, for I know the world has enough IRC clients to piss a dog off. So why exactly am I making one? The answer is simple: I want experience, and the thrill of making something that could be useful one day is a factor in this too.
I'm using C++ and Winsock2 for this project, after countless hours wasted today through trial and error, I finally managed to get it to successfully connect to a SlashNet IRC server... or so it said.
I'm not receiving any messages from the server, yet I'm sending it. Maybe I'm doing something wrong but will I ever know? Yes, probably, but I'd rather not figure this out for myself. I'm asking for the help of anyone who could possibly understand this problem, unless I figure it out before then, and that would truly be a miracle.
Bear in mind I just began learning socket programming and IRC protocol today, and this is what I came up with thanks to a few nifty tutorials on winsock2.
#include <iostream>
#include <winsock2.h>
using namespace std;
char buffer[512];
int received;
int main(int argc, char *argv[])
{
WSADATA wsaData;
if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
{
cout << "Error: " << WSAGetLastError() << " occurred!" << endl;
system("PAUSE >nul");
WSACleanup();
return 0;
}
cout << "WSAStartup Successful!" << endl;
system("PAUSE >nul");
SOCKET mysock = socket(AF_INET, SOCK_STREAM, 0);
if(mysock == INVALID_SOCKET)
{
cout << "Error: " << WSAGetLastError() << " occurred!" << endl;
system("PAUSE >nul");
WSACleanup();
return 0;
}
cout << "Socket creation successful!" << endl;
system("PAUSE >nul");
sockaddr_in anews;
anews.sin_port = htons(6697);
anews.sin_addr.s_addr = inet_addr("38.99.109.26");
anews.sin_family = AF_INET;
if(connect(mysock, (sockaddr*)&anews, sizeof(anews)) == SOCKET_ERROR)
{
cout << "Error: " << WSAGetLastError() << " occurred!" << endl;
system("PAUSE >nul");
WSACleanup();
return 0;
}
cout << "Socket has connected successfully!" << endl;
char *data = "NICK RCBot\n";
cout << data << endl;
send(mysock, data, strlen(data), 0);
data = "USER rcbot \"live.com\" \"irc.slashnet.org\" :Rcbot\n";
cout << data << endl;
send(mysock, data, strlen(data), 0);
while(true)
{
received = recv(mysock,buffer,1023,0);
if(received > 0)
{
char *result = NULL;
result = strtok(buffer, "\n");
while(result != NULL)
{
cout << result << endl;
}
}
}
system("PAUSE >nul");
closesocket(mysock);
WSACleanup();
return 0;
}
That's the source so far, I know I'm not ponging back the ping, but that's not necessary right now since I'm not even being pinged!
Edit: Never mind, I figured out I had the wrong port. Still, I'm getting an infiloop of ":moo.slashnet.org NOTICE AUTH :*** Looking up your hostname..."