0 Members and 1 Guest are viewing this topic.
#include "Client.h"void Client::Init( std::string server ){ Server.SetBlocking( false ); ServerAddress = server; do { } while (!ServerAddress.IsValid()); if ( Server.Connect(Port, ServerAddress) == sf::Socket::Done ) { IsConnected = false; std::cout << "Blad przy laczeniu z serwerem " << ServerAddress << std::endl; } else if ( Server.Connect(Port, ServerAddress) == sf::Socket::Done ) { IsConnected = true; std::cout << "Polaczono z serwerem " << ServerAddress << std::endl; } else if ( Server.Connect(Port, ServerAddress) == sf::Socket::NotReady ) { std::cout << "Trwa laczenie z " << ServerAddress << std::endl; } else if ( Server.Connect(Port, ServerAddress) == sf::Socket::Disconnected ) { std::cout << "Utracono polaczenie z " << ServerAddress << std::endl; }}void Client::Recv(){ Server.Receive( Buffer, sizeof( Buffer ), Rec ); std::cout << Buffer << std::endl;}
#include <iostream>#include "Client.h"int main(){ Client GameClient; std::string serv; std::cout << "Podaj ip" << std::endl; std:: cin >> serv; GameClient.Init( serv ); while( true ) { if( GameClient.IsConnected == false ) { } else if( GameClient.IsConnected == true ) { GameClient.Recv(); } }}