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

Pages: [1]
1
Network / Failed to bind the socket to port 5200?
« on: June 10, 2009, 01:38:41 am »
Ich have the solution...

This works:
Code: [Select]
   void Receive()
    {
        if ( !GetClientInfo() ) { return; };
        if ( !SendClientInfo() ) { return; };

        sf::SocketUDP m_ClientUDP;
        bool bValid = 0;
        int ErrorVal = 0;
        sf::IPAddress Address;
        unsigned short Port = 5200;

        bValid = m_ClientUDP.IsValid();
        m_ClientUDP.Unbind();
        bValid = m_ClientUDP.Bind( Port );
        ErrorVal = WSAGetLastError();
        std::cout << "WSAGetLastError: " << ErrorVal << std::endl;
        while (1)
        {
            sf::Packet DataPacket;
            if (m_ClientUDP.Receive(DataPacket, Address, Port) != sf::Socket::Done)
            {
                return;
            }
            std::cout << "Got Data: " << DataPacket.GetDataSize() << " Bytes" << std::endl;

            sf::Sleep( m_Ping );
        }
    };


Declaring the Socket as local Variable works - I think the Stack gets corrupted before CNetTest::Receive() is called.

2
Network / Failed to bind the socket to port 5200?
« on: June 09, 2009, 11:39:22 pm »
Quote from: "Laurent"
Please send a minimal and complete code so that I can test it directly.

Which version of SFML are you using? Which OS?

SFML-Version 1.5, dynamic Lib
OS: Vista 32-bit Home Premium
Compiler: MSVC08, IDE: Codeblocks

This program is for testing purposes only, here's the complete Code:
Code: [Select]
#include <iostream>
#include <SFML\Network.hpp>


struct s_InfoPlayer
{
    sf::Uint8 Address[16];
    sf::Uint8 Nick[20];
    void Clear() { memset( this, 0, sizeof(s_InfoPlayer) ); };
};

class CNetTest
{
private:
    sf::SocketTCP m_Listener;
    sf::SocketTCP m_ClientTCP;
    sf::SocketUDP m_ClientUDP;
    float m_Ping;
private:
    bool GetClientInfo()
    {
        size_t iCount = 0;
        sf::Uint32 iBuild = 0;
        s_InfoPlayer PlayerInfo;

        if (m_ClientTCP.Receive( (char*)&iBuild, sizeof(sf::Uint32), iCount) != sf::Socket::Done) { return 0; }
        if (m_ClientTCP.Receive( (char*)&PlayerInfo, sizeof(s_InfoPlayer), iCount) != sf::Socket::Done) { return 0; }

        std::cout << "Client Build " << iBuild << std::endl;
        std::cout << "Added Client " << PlayerInfo.Nick << std::endl;
        return 1;
    };

    bool SendClientInfo()
    {
        std::string sNick("NetTest");
        std::string sAddress("127.0.0.1");
        s_InfoPlayer PlayerInfo; PlayerInfo.Clear();

        sNick.copy( (char*)&PlayerInfo.Nick[0], sizeof(PlayerInfo.Nick) );
        sAddress.copy( (char*)&PlayerInfo.Address[0], sizeof(PlayerInfo.Address) );
        m_ClientTCP.Send( (char*)&PlayerInfo, sizeof(s_InfoPlayer) );

        std::cout << "Sent Client-Info" << std::endl;
        return 1;
    };
public:
     CNetTest()
    {
        m_Ping = 0.1f;

        std::cout << "Listening..." << std::endl;
        m_Listener.Listen( 5100 );
        m_Listener.Accept(m_ClientTCP, 0);
        std::cout << "Host connected!" << std::endl;
    };

    void Receive()
    {
        if ( !GetClientInfo() ) { return; };
        if ( !SendClientInfo() ) { return; };

        bool bValid = 0;
        int ErrorVal = 0;
        sf::IPAddress Address;
        unsigned short Port = 5200;

        bValid = m_ClientUDP.IsValid();
        m_ClientUDP.Unbind();
        bValid = m_ClientUDP.Bind( Port );
        ErrorVal = WSAGetLastError();
        std::cout << "WSAGetLastError: " << ErrorVal << std::endl;
        while (1)
        {
            sf::Packet DataPacket;
            if (m_ClientUDP.Receive(DataPacket, Address, Port) != sf::Socket::Done)
            {
                return;
            }
            std::cout << "Got Data: " << DataPacket.GetDataSize() << " Bytes" << std::endl;

            sf::Sleep( m_Ping );
        }
    };

    ~CNetTest() { m_Listener.Close(); m_ClientTCP.Close(); m_ClientUDP.Close(); };
};


int main()
{
    CNetTest NetTest;
    NetTest.Receive();

    std::cout << std::endl << "Host disconnected..." << std::endl;
    system("pause");
    return 0;
};


And the UDP-Part:
Code: [Select]
   void Receive()
    {
        if ( !GetClientInfo() ) { return; };
        if ( !SendClientInfo() ) { return; };

        bool bValid = 0;
        int ErrorVal = 0;
        sf::IPAddress Address;
        unsigned short Port = 5200;

        bValid = m_ClientUDP.IsValid();
        m_ClientUDP.Unbind();
        bValid = m_ClientUDP.Bind( Port );
        ErrorVal = WSAGetLastError();
        std::cout << "WSAGetLastError: " << ErrorVal << std::endl;
        while (1)
        {
            sf::Packet DataPacket;
            if (m_ClientUDP.Receive(DataPacket, Address, Port) != sf::Socket::Done)
            {
                return;
            }
            std::cout << "Got Data: " << DataPacket.GetDataSize() << " Bytes" << std::endl;

            sf::Sleep( m_Ping );
        }
    };


After the bind I get this WinSock-Error: WSAENOTSOCK 10038

3
Network / Failed to bind the socket to port 5200?
« on: June 09, 2009, 09:48:36 pm »
I get this as console output:
Quote
Failed to bind the socket to port 5200
Failed to receive data ; the UDP socket first needs to be bound to a port


The Code:
Code: [Select]

        sf::IPAddress Address;
        unsigned short Port = 5200;
        m_ClientUDP.Bind( Port );
        while (1)
        {
            sf::Packet DataPacket;
            if (m_ClientUDP.Receive(DataPacket, Address, Port) != sf::Socket::Done)
            {
                return;
            }
            std::cout << "Got Data: " << DataPacket.GetDataSize() << " Bytes" << std::endl;

            sf::Sleep( m_Ping );
        }


My Firewall was off and the connecection was local (127.0.0.1).
Edit: I have the same Problems on other Ports (ex. 51000).

4
Network / [Problem fixed] Receiving more Data then sent
« on: June 09, 2009, 04:09:26 am »
Problem fixed.

Client-Side Code:
Code: [Select]

    m_Socket.Send( (char*)&iBuild, sizeof(sf::Uint32) );
    m_Socket.Send( (char*)&LocalInfo, sizeof(s_InfoPlayer) );

5
Network / [Problem fixed] Receiving more Data then sent
« on: June 09, 2009, 03:28:28 am »
I have a Problem with Receiving directly after making a connection.
The Data I receive is not broken, but there are 4 Byte Data before my sent Data...

Client-Side Code:
Code: [Select]
   NetPacket.Append( &iBuild, sizeof(sf::Uint32) );
    NetPacket.Append( &LocalInfo, sizeof(s_InfoPlayer) );
    m_Socket.Send( NetPacket );


Server-Side Code:

That works:
Code: [Select]

        if (m_Client.Receive( (char*)&SomeData, sizeof(sf::Uint32), iCount) != sf::Socket::Done) { return; }
        if (m_Client.Receive( (char*)&iBuild, sizeof(sf::Uint32), iCount) != sf::Socket::Done) { return; }
        if (m_Client.Receive( (char*)&PlayerInfo, sizeof(s_InfoPlayer), iCount) != sf::Socket::Done) { return; }


That dont works:
Code: [Select]

        if (m_Client.Receive( (char*)&iBuild, sizeof(sf::Uint32), iCount) != sf::Socket::Done) { return; }
        if (m_Client.Receive( (char*)&PlayerInfo, sizeof(s_InfoPlayer), iCount) != sf::Socket::Done) { return; }


Greetings

Pages: [1]
anything