Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: simple client  (Read 2448 times)

0 Members and 1 Guest are viewing this topic.

Trol

  • Newbie
  • *
  • Posts: 3
    • View Profile
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 :P

Mars_999

  • Full Member
  • ***
  • Posts: 103
    • View Profile
    • Email
Re: simple client
« Reply #1 on: April 09, 2012, 01:03:00 am »
You can check out my tutorial in the wiki... It may help...