All pastes #349197 Raw Edit

Stuff

public cpp v1 · immutable
·published 2007-02-10 17:05 UTC
rendered paste body
//Client to Aaron's fileserver//Author  $ Dylan Johnston//Connect $ bitforge.redirectme.net:404//Notes   $ Win-sock-two#include <cstdlib>#include <iostream>#include <string>#include <windows.h>#include <winsock2.h>#include <ws2tcpip.h>using namespace std;const string DEBUG  = "[debug]: "; //just to make things clear in the console :)char serverAddress[128];int main(){  int iResult;  WSADATA wsaData; //start winsock  iResult = WSAStartup(MAKEWORD(2,2), &wsaData);  if (iResult != 0) {   cout << DEBUG << "failed" << iResult << "\n";  } else {     if (iResult == 0) {   cout << DEBUG << "success" << "\n";   cout << DEBUG << "starting up winsock\n";   // Create a SOCKET for connecting to server   SOCKET ConnectSocket;   ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);   if (ConnectSocket == INVALID_SOCKET)    {    cout << DEBUG << "error " << WSAGetLastError();    WSACleanup();   }    // The sockaddr_in structure specifies the address family,   // IP address, and port of the server to be connected to.   sockaddr_in clientService;    clientService.sin_family = AF_INET;   clientService.sin_addr.s_addr = inet_addr( "209.85.135.103" );   clientService.sin_port = htons( 80 );   addrinfo *aiList = 0;   addrinfo aiHints = {0};   aiHints.ai_family = AF_UNSPEC;   aiHints.ai_socktype = SOCK_STREAM;   aiHints.ai_protocol = IPPROTO_TCP;   cout << "address: ";   cin >> serverAddress;    if (getaddrinfo( serverAddress, "3690", &aiHints, &aiList ) != 0 )     {     closesocket( ConnectSocket );     WSACleanup();     return 0;     }       // Connect to server.   if ( connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) {    cout << DEBUG << "failed connection" << "\n";    WSACleanup();    system("Pause");    return 0;   }   cout << DEBUG << "connected!";   WSACleanup(); //that's 1   } //that's 2 } ALOT OF THINGS!  } //that's 3   system("Pause");  return 0;}