Advertisement
thecplusplusguy

SDL tutorial 25 - client.cpp

Jul 17th, 2012
2,659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. //http://www.youtube.com/user/thecplusplusguy
  2. //a simple client for networking with SDL_Net
  3. #include <iostream>
  4. #include <SDL/SDL.h>
  5. #include <SDL/SDL_net.h>
  6. #include <cstring>
  7.  
  8. int main(int argc,char** argv)
  9. {
  10.     SDL_Init(SDL_INIT_EVERYTHING);
  11.     SDLNet_Init();
  12.    
  13.     IPaddress ip;
  14.     //write "127.0.0.1",1234 to connect to the server.cpp on your local machine
  15.     SDLNet_ResolveHost(&ip,"www.linux.org",80);
  16.  
  17.     const char* http="GET / HTTP/1.1\nHost: www.linux.org\n\n";
  18.  
  19.     TCPsocket client=SDLNet_TCP_Open(&ip);
  20.  
  21.     SDLNet_TCP_Send(client,http,strlen(http)+1);
  22.  
  23.     char text[10000];
  24.  
  25.     while(SDLNet_TCP_Recv(client,text,10000))
  26.         std::cout << text;
  27.    
  28.     SDLNet_TCP_Close(client);
  29.    
  30.     SDLNet_Quit();
  31.     SDL_Quit();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement