Created
December 29, 2013 04:13
-
-
Save TrainerGuy22/8167370 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Connect to the current connection. */ | |
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'; | |
assert(0 != send(socketNum, chatBuffer, 500, 0)); | |
assert(-1 != sprintf(chatBuffer, "USER SeePlusPlus * 8 :SeePlusPlus")); | |
cout << chatBuffer << '\n'; | |
assert(0 != 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