Skip to content

Instantly share code, notes, and snippets.

@TrainerGuy22
Created December 29, 2013 04:02
Show Gist options
  • Save TrainerGuy22/8167252 to your computer and use it in GitHub Desktop.
Save TrainerGuy22/8167252 to your computer and use it in GitHub Desktop.
void Connection::connectToServer() {
char chatBuffer[500];
struct addrinfo *serverInfo;
assert(0 == getaddrinfo(this->domainAddress.c_str(), this->portNumber.c_str(), NULL, &serverInfo));
int socketNum = socket(serverInfo->ai_family, serverInfo->ai_socktype, serverInfo->ai_protocol);
cout << *(*(*serverInfo).ai_addr).sa_data;
assert(0 == connect(socketNum, serverInfo->ai_addr, serverInfo->ai_addrlen));
cout << "Woo!" << '\n';
assert(-1 != sprintf(chatBuffer, "NICK SeePlusPlus"));
cout << chatBuffer << '\n';
send(socketNum, chatBuffer, 500, 0);
assert(-1 != sprintf(chatBuffer, "USER SeePlusPlus * 8 :SeePlusPlus"));
cout << chatBuffer << '\n';
send(socketNum, chatBuffer, 500, 0);
while(true) {
int sizeFromPacket = recv(socketNum, chatBuffer, 500, 0);
if(sizeFromPacket != -1) {
cout << chatBuffer;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment