Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Network.hpp>
- #include <SFML/Graphics.hpp>
- #include <iostream>
- const unsigned int MAX_PACKET_SIZE=100;
- void sendFeedback(std::string message)
- {
- std::cout << "Checking message length...\n";
- if (message.length() >=100)
- {
- std::cout << "ERROR: Message too long\n";
- return;
- }
- std::cout << "Binding to the sender socket...\n";
- sf::UdpSocket socket;
- std::cout << "--Socket initialized...\n";
- if (socket.bind(8009) !=sf::Socket::Done)
- {
- std::cout << "ERROR: Couldn't bind to send port\n";
- return;
- }
- std::cout << "Successfully started; sending message...\n";
- sf::IpAddress server("127.0.0.1");
- unsigned short serverPort=58008;
- std::size_t numBytes;
- char data[MAX_PACKET_SIZE];
- int remaining=0;
- for (unsigned int i=0; i<MAX_PACKET_SIZE && i < message.length(); ++i)
- {
- data[i]=message[i];
- remaining=i;
- }
- data[remaining+1]='\0';
- if (socket.send(data, MAX_PACKET_SIZE, server, serverPort) !=sf::Socket::Done)
- {
- std::cout << "ERROR: Couldn't send to server\n";
- }
- }
- int main()
- {
- std::cout << "Attempting to initialize *something* SFML\n";
- sf::Text text;
- std::cout << "Attempting to send message now...\n";
- sendFeedback("Hello, this is a feedback message");
- std::cout << "All done!\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement