1
Network / simple client
« on: March 31, 2012, 10:11:38 am »
Hello i want write a client/server to my game but i have problem with connection server show me client is connected but client don't do that : / what i do wrong?
Code: [Select]
#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;
}
Code: [Select]
#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();
}
}
}
sorry for my english