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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - renansouzones

Pages: [1]
1
Network / Re: Trying to communicate with packages
« on: June 09, 2015, 07:10:11 pm »
Unfortunately it's going to be really hard to both master network practices and deliver this project in time (as this is supposed to be done by Friday), but I followed your advice and tried to do it less complicated - instead of sending the whole "Carta" class, I'm sending only its values:

int main()
{
        Servidor s;

        sf::Packet j0;
       
        if (eServer == true) // there is a boolean here to set if it's the server or a cliente
        {
                sf::TcpListener listener;
                listener.listen(2000);
                listener.accept(socket);

                s.novoTurno();

// all the values below represent 3 cards with 4 variables each
                j0 << s.getJogador(0).getMaoCartas(0).getNumero() << s.getJogador(0).getMaoCartas(0).getNaipe() << s.getJogador(0).getMaoCartas(0).getValor() << s.getJogador(0).getMaoCartas(0).getImagem() << s.getJogador(0).getMaoCartas(1).getNumero() << s.getJogador(0).getMaoCartas(1).getNaipe() << s.getJogador(0).getMaoCartas(1).getValor() << s.getJogador(0).getMaoCartas(1).getImagem() << s.getJogador(0).getMaoCartas(2).getNumero() << s.getJogador(0).getMaoCartas(2).getNaipe() << s.getJogador(0).getMaoCartas(2).getValor() << s.getJogador(0).getMaoCartas(2).getImagem();
               
                socket.send(j0); // this is where the cards are supposed to be sent

                while (servLoop == true)
                {
                       
                }
        }
        else
        {
                socket.connect(sf::IpAddress::getLocalAddress(), 2000);

                Controlador c(width, height, title); // client's class

                Carta c1, c2, c3;
                int nm1, np1, vl1,
                        nm2, np2, vl2,
                        nm3, np3, vl3;
                std::string im1, im2, im3;

                socket.receive(j0);
       
                j0 >> nm1 >> np1 >> vl1 >> im1 >> nm2 >> np2 >> vl2 >> im2 >> nm3 >> np3 >> vl3 >> im3;

                c1.setNumero(nm1);
                c1.setNaipe(np1);
                c1.setValor(vl1);
                c1.setImagem(im1);
                c2.setNumero(nm2);
                c2.setNaipe(np2);
                c2.setValor(vl2);
                c2.setImagem(im2);
                c3.setNumero(nm3);
                c3.setNaipe(np3);
                c3.setValor(vl3);
                c3.setImagem(im3);
               
                c.getJogador().setMaoCartas(0, c1);
                c.getJogador().setMaoCartas(1, c2);
                c.getJogador().setMaoCartas(2, c3);

                c.defineCartas(); // cards received and stored in client's class

                while (c.getWindow().isOpen())
                {
                        sf::Event event;

                        while (c.getWindow().pollEvent(event))
                        {
                                if (event.type == sf::Event::Closed){ c.getWindow().close(); }

                                eventosMouse(event);

                                c.getWindow().clear();
                                c.abreJogo();
                                c.getWindow().display();
                        }
                }
        }
       
        return 0;
}


The Client part is working just fine, but the Server's isn't. I run the Server and it's listener keep waiting until a Client connect - when it does, the project running the Server crashes and only the Client keeps running (and it obviously can't read the cards because it didn't receive any). Where exactly am I doing wrong?

I understand the problem here is my lack of knowledge and I agree with you. I am reading everything I can about SFML network in the few free time I have, although I face many difficulties understanding this part. The main problem here is the deadline (this Friday) to deliver this, that's why I'm comming to you with these questions. Sorry for any inconvenience. :(

2
Network / Re: Trying to communicate with packages
« on: June 09, 2015, 03:56:51 am »
I modified the previous operator and changed for this:

class CardPacket : public sf::Packet
{
        virtual const void* onSend(std::size_t& size)
        {
                const void* srcData = getData();
                return srcData;
        }
        virtual void onReceive(const void* data, std::size_t size)
        {
                append(data, size);
        }
};

But now there are errors every time I write something like "CardPacket j0 << s.getJogador(0);". What did I do wrong?

3
Network / Trying to communicate with packages
« on: June 08, 2015, 09:41:16 pm »
Hi everyone!  :D

Well, this is my first time using SFML Network  - actually, that's my first time working on a network project at all. I have no previous experiences handling networks of any kind, so please forgive me if I am asking easy questions.

So: I'm working on a card game and there will be two sides: Server and Client. The Server will be responsible for hosting all players cards and each action performed by them will be sent to the Server. To exchange data between them, I'm using SFML packages.

There is a class named "Jogador" (which stands for "Player" in portuguese) and inside that class there are three instances of another class named "Carta" ("Card"). In other words, each player has three cards. These players are defined inside the Server and then sent to the Client via packages so they can be drawn on the Client's screen. There are also two other main classes: "Servidor" ("Server") and "Controlador" ("Controller", where the game itself will run).

This is the main.cpp so far (questions right below it):

#include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\Network.hpp>
#include "Servidor.h"
#include "Controlador.h"
#include "Jogador.h"

sf::TcpSocket socket;
char conexao;
char buffer[2000];
size_t recebido;

bool eServidor = false;
bool servLoop = false;

sf::Packet& operator <<(sf::Packet& packet, const Jogador& jogador)
{
        return packet << jogador;
}

sf::Packet& operator >>(sf::Packet& packet, const Jogador& jogador)
{
        return packet >> jogador;
}

int main()
{
        Servidor s;

        s.novoTurno(); // this is where the cards of each player are being defined

        sf::Packet j0, j1, j2, j3, j4, j5;                              // each packet represents a player
        j0 << s.getJogador(0);
        j1 << s.getJogador(1);
        j2 << s.getJogador(2);
        j3 << s.getJogador(3);
        j4 << s.getJogador(4);
        j5 << s.getJogador(5);

        std::cout << "Hit (s) for server or (c) for client: \n";
        std::cin >> conexao;

        if (conexao == 's')
        {
                texto += "server";
                eServidor = true;
                servLoop = true;
        }
        else if (conexao == 'c')
        {
                texto += "client";
        }

        if (eServidor == true)
        {
                sf::TcpListener listener;
                listener.listen(2000);
                listener.accept(socket);

                socket.send(j0); // sends all player information to the clients
                socket.send(j1);
                socket.send(j2);
                socket.send(j3);
                socket.send(j4);
                socket.send(j5);
                std::cout << "Cartas enviadas.\n";

                while (servLoop == true)
                {
                       
                }
        }
        else
        {
                socket.connect(sf::IpAddress::getLocalAddress(), 2000);

                Controlador c(width, height, title); // handles client actions

                socket.receive(j0); // receive player data from the server

                Jogador jg;
               
                j0 >> jg;

                c.defineCartas(jg); // defines the client's player data (get from Server)

                while (c.getWindow().isOpen())
                {
                        sf::Event event;

                        while (c.getWindow().pollEvent(event)) 
                        {
                                if (event.type == sf::Event::Closed){ c.getWindow().close(); }

                                eventosMouse(event);

                                c.getWindow().clear();
                                c.abreJogo(); // this is where the cards are being displayed on the screen
                                c.getWindow().display();
                        }
                }
        }
       
        return 0;
}

When trying to execute it, I have a stack overflow error right in the part of the code with the "operator" - in the upper side. I did that coding because I'm sending custom classes through the packages (I saw that on SFML documentation):

sf::Packet& operator <<(sf::Packet& packet, const Jogador& jogador)
{
        return packet << jogador;
}

Did I do something wrong through the code?

Also, if you observed something else I did wrong please notify me as I lack experience on Network area (not only in SFML) and there is a good chance I'm doing something awful. :P

Thanks in advance!

4
General / Re: Problem concerning 'X86' machine type
« on: May 13, 2014, 06:23:19 am »
Now I understand. Basic mistake of mine, then. Thank you very much for your help! :D

5
General / Problem concerning 'X86' machine type
« on: May 13, 2014, 03:48:02 am »
Hi guys,

I'm starting a SFML project on Visual Studio 2010 and the program is not compilling due to the following error:

Error   1   error LNK1112: module machine type 'x64' conflicts with target machine type 'X86' (sfml-graphics.lib)

The problem concerning this is that I've only found downloads for x64 and x32 machines at the website - none of them were specific for x86 machines. I'm currently using the x64 files and I believe that's what causing the problem to not compile.

Is there any way I can fix this?

Thanks in advance!  ;D

Pages: [1]
anything