Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////
- // Headers
- ////////////////////////////////////////////////////////////
- #include <SFML/Window.hpp>
- #include <SFML/System.hpp>
- #include <SFML/Graphics.hpp>
- #include <SFML/Network.hpp>
- #include <string>
- #include <iostream>
- using namespace std;
- bool firstrun = true;
- bool DebugPause = true;
- bool debuging = false;
- // METHOD Debug
- bool debug(string message) {
- if (debuging) {
- cout << "\nDEBUG " << message << "\n";
- if (DebugPause) {
- int x;
- cin.getline(cin,x);
- }
- return true;
- } else {
- return false;
- }
- }
- int main() {
- if (firstrun) {
- // TODO Spaces Screw things up!
- cout << "Username: ";
- string name = "";
- getline(cin, name);
- debug("Got name");
- while (name == "" || name == " ") {
- cout << "Invalid Enter a new name: ";
- debug("Name was invalid");
- getline(cin, name);
- cout << "\n";
- }
- }
- debug("Asking for the mode");
- cout << "LAN (1) or Net (0): ";
- int type;
- debug("Declared Variable");
- getline(cin,type);
- debug("Asked for input");
- // Remeber it does not need to be inverted
- // because if it is it runs the loop if it is larger or smaller
- while (type < 0 && type >= 3) {
- cout << "Invalid LAN (1) or Net (0): ";
- cout << "\n";
- getline(cin,type);
- }
- cout << "\n";
- // Create the UDP socket
- debug("Creating socket");
- sf::SocketUDP Socket;
- debug("Binding socket");
- // Bind it (listen) to the port 4567
- if (!Socket.Bind(4567)) {
- cout << "Error Socket could not be bound (Very Bad Thing TM)";
- return -1;
- }
- char Buffer[] = "";
- cout << "What do you want to send?";
- getline(cin, Buffer);
- if (Socket.Send(Buffer, sizeof(Buffer), "192.168.0.2", 4567) != sf::Socket::Done) {
- cout << "Could not send buffer! (Connection error)";
- }
- debug("Closing socket");
- if (!Socket.Close()) {
- cout << "Error Socket could not be closed (Very Bad Thing TM), If you have isues restart.";
- return -2;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement