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 - JeromeBaur

Pages: [1]
1
Window / Mouse Click without isButtonPressed
« on: October 25, 2011, 06:44:34 pm »
Hey

I tryed first to simulate a click on a button and i used:

Code: [Select]
if(sf::Mouse::IsButtonPressed(sf::Mouse::Left))

I don't know, probably it's a click but the programm don't reacte on the click sometimes and i have to click 5-10 times and press doesn't work everytime.


How can i solve this? I checked and the mouse(in the code) is on the button.

I hope you can help me =)

2
Network / Tcp Selector
« on: October 20, 2011, 04:15:04 pm »
Hey guys

I use SFML 2.0 Network because the 1.6 version of network doesn't work by me. But SFML 2.0 has only 1 example of socket. I want to make a selector for a online Game. I used the old example from version 1.6 and changed the code for example SocketTcp to TcpSocket. Now i have a problem. In SFML 1.6 i can compare a Listener with a Socket but in 2.0 that doesn't work.  :cry:


Can someone give me a example how i can use selectors in 2.0?

Here's the code of the serverfunction:

Code: [Select]
void DoServer(unsigned short Port)
{
    // Create a socket for listening to incoming connections
    sf::TcpListener Listener;
    std::cout << "Listening to port " << Port << ", waiting for connections..." << std::endl;

    // Create a selector for handling several sockets (the listener + the socket associated to each client)
    sf::SocketSelector Selector;

    // Add the listener
    Selector.Add(Listener);

    // Loop while... we close the program :)
    std::vector<sf::TcpSocket> SocketsReady;
    while (true)
    {
        // Get the sockets ready for reading
        //Selector.IsReady(SocketsReady);

        // We can read from each returned socket
for (std::vector<sf::TcpSocket>::iterator i = SocketsReady.begin(); i != SocketsReady.end(); ++i)
        {
            // Get the current socket
            sf::TcpSocket Socket = *i;

if (Listener == Socket )
            {
                // If the listening socket is ready, it means that we can accept a new connection
                sf::IpAddress Address;
                sf::TcpSocket Client;
                Listener.Accept(Socket);
                std::cout << "Client connected ! (" << Address << ")" << std::endl;

                // Add it to the selector
                Selector.Add(Client);
            }
            else
            {
                // Else, it is a client socket so we can read the data he sent
                sf::Packet Packet;
                if (Socket.Receive(Packet) == sf::Socket::Done)
                {
                    // Extract the message and display it
                    std::string Message;
                    Packet >> Message;
                    std::cout << "A client says : \"" << Message << "\"" << std::endl;
                }
            }
        }
    }
}


I hope you can help me.

Thx a lot =)

Pages: [1]
anything