<pre lang="C++"> <pre>#include <iostream> #include<SFML/Network.hpp> using namespace std; int main() { string lolz; cout << "C[CLIENT]/S[SERVER] : "; cin >> lolz; if (lolz.compare("S") == 0) { sf::UdpSocket socket; socket.bind(55002); char buffer[1024]; std::size_t received = 0; sf::IpAddress sender; unsigned short port; socket.receive(buffer, sizeof(buffer), received, sender, port); std::cout << sender << " CLIENT SEND YOU : : " << buffer << std::endl; std::string message = "From server : Response is [ok]" + sender.toString(); socket.send(message.c_str(), message.size() + 1, sender, port); } else if (lolz.compare("C") == 0){ string ipSer; cout << "SERVER IP : "; cin >> ipSer; sf::UdpSocket socket; socket.bind(55001); // Send a message to IP on port 55002 std::string message = "FROM CLIENT : [ok] " + sf::IpAddress::getLocalAddress().toString(); socket.send(message.c_str(), message.size() + 1, ipSer, 55002); char buffer[1024]; std::size_t received = 0; sf::IpAddress sender; unsigned short port; socket.receive(buffer, sizeof(buffer), received, sender, port); std::cout << sender << " SERVER SEND YOU : : " << buffer << std::endl; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)