Advertisement
Guest User

Code

a guest
Mar 26th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////
  2. // Headers
  3. ////////////////////////////////////////////////////////////
  4. #include <SFML/Window.hpp>
  5. #include <SFML/System.hpp>
  6. #include <SFML/Graphics.hpp>
  7. #include <SFML/Network.hpp>
  8. #include <string>
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13.  
  14. bool firstrun = true;
  15. bool DebugPause = true;
  16. bool debuging = false;
  17.  
  18. // METHOD Debug
  19. bool debug(string message) {
  20.     if (debuging) {
  21.         cout << "\nDEBUG " << message << "\n";
  22.         if (DebugPause) {
  23.             int x;
  24.             cin.getline(cin,x);
  25.         }
  26.         return true;
  27.     } else {
  28.         return false;
  29.     }
  30. }
  31.  
  32. int main()  {
  33.  
  34.     if (firstrun) {
  35.         // TODO Spaces Screw things up!
  36.         cout << "Username: ";
  37.         string name = "";
  38.         getline(cin, name);
  39.         debug("Got name");
  40.         while (name == "" || name == " ") {
  41.             cout << "Invalid Enter a new name: ";
  42.             debug("Name was invalid");
  43.             getline(cin, name);
  44.             cout << "\n";
  45.         }
  46.     }
  47.     debug("Asking for the mode");
  48.     cout << "LAN (1) or Net (0): ";
  49.     int type;
  50.     debug("Declared Variable");
  51.     getline(cin,type);
  52.     debug("Asked for input");
  53.     // Remeber it does not need to be inverted
  54.     // because if it is it runs the loop if it is larger or smaller
  55.     while (type < 0 && type >= 3) {
  56.         cout << "Invalid LAN (1) or Net (0): ";
  57.         cout << "\n";
  58.         getline(cin,type);
  59.     }
  60.     cout << "\n";
  61.  
  62.     // Create the UDP socket
  63.     debug("Creating socket");
  64.     sf::SocketUDP Socket;
  65.     debug("Binding socket");
  66.     // Bind it (listen) to the port 4567
  67.     if (!Socket.Bind(4567)) {
  68.         cout << "Error Socket could not be bound (Very Bad Thing TM)";
  69.         return -1;
  70.     }
  71.  
  72.  
  73.     char Buffer[] = "";
  74.  
  75.     cout << "What do you want to send?";
  76.     getline(cin, Buffer);
  77.  
  78.     if (Socket.Send(Buffer, sizeof(Buffer), "192.168.0.2", 4567) != sf::Socket::Done)   {
  79.         cout << "Could not send buffer! (Connection error)";
  80.     }
  81.  
  82.  
  83.     debug("Closing socket");
  84.     if (!Socket.Close()) {
  85.         cout << "Error Socket could not be closed (Very Bad Thing TM), If you have isues restart.";
  86.         return -2;
  87.     }
  88.  
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement