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

Pages: [1]
1
Network / Re: Server such as Apache
« on: June 10, 2018, 11:32:13 am »
I am accepting the requests, the image shows one request to localhost:80 from Firefox which then makes another four requests for the data missing(see in network traffic)


And here's the network traffic:
(click to show/hide)

I implemented the method to receive data from a TcpSocket in Client to try the system in general. A communication of my Client and my Server worked well. But with the exact same implementation the server doesn't receive anything from firefox (seen in 1st image).

2
Network / Server such as Apache
« on: June 09, 2018, 11:55:17 pm »
I've written a little application that sends an index.html to connected clients simultaneously. When I connect to that server in Firefox it displays the website as wished. So far so good.
My problem now is that Firefox then sends more requests to receive more data like images and so on. So I thought: well, I just call receive() on that new TcpSocket to identify the files Firefox wants. But I ended up with the problem that receive() doesn't give me (the server) any output.

Some Code:
void Server::ServeClient( ClientServeParams_t* ServeParams )
{
        ClientServeParams_t ClientServeParams = *ServeParams;
        delete ServeParams;

#ifdef HTTP
        ClientServeParams.ClientSocket->setBlocking( false );
        CCL::String RecvData;
        sf::Socket::Status recvStatus = sf::Socket::Status::NotReady;
        int fails = 0;
        do
        {
                sf::Packet Packet;
                recvStatus = ClientServeParams.ClientSocket->receive( Packet );
                if ( recvStatus == sf::Socket::Status::Done )
                {
                        RecvData.append( (char*) Packet.getData( ) );
                        RecvData.resize( Packet.getDataSize( ) );
                }
                else
                        fails++;
        } while ( recvStatus != sf::Socket::Status::Done && fails < 3 );
        CCL::System::IO::Console::WriteLineFmtColor( CCL::System::IO::Console::Color::RED, "[SERVER] Client % sent: %", { ClientServeParams.Client_ID, RecvData } );
        ClientServeParams.ClientSocket->setBlocking( true );


        char TempPath[MAX_PATH];
        HMODULE hModule = GetModuleHandleA( NULL );
        if ( hModule != NULL )
                GetModuleFileNameA( hModule, TempPath, ( sizeof( TempPath ) ) );
        CCL::String AppPath( TempPath );
        AppPath.resize( AppPath.find_last_of( '\\' ) );

        CCL::System::IO::Directory Root( CCL::String( AppPath ) + "/html/" );
        if ( Root.Exists( ) )
        {
                CCL::System::IO::File Index( Root.GetPath( ) + "index.html" );

                CCL::String Data;
                Index.Read( Data );
                CCL::String SendData = "HTTP/1.1 200 OK\nContent-length: " + CCL::String( Data.size( ) ) + "\nContent-Type: text/html\n\n" + Data;

                sf::Packet Packet;
                Packet.append( SendData.ToConstCharArray( ), SendData.size( ) );
                sf::Socket::Status status = ClientServeParams.ClientSocket->send( Packet );
                if ( status != sf::Socket::Done )
                {
                        CCL::System::IO::Console::WriteLineFmtColor( CCL::System::IO::Console::Color::RED, "[SERVER] Client % lost Connection.", { ClientServeParams.Client_ID } );
                }
        }

#else

        while ( true )
        {
                CCL::String Data = "[" + CCL::String( ClientServeParams.Client_ID ) + "] " + CCL::String( GetTickCount( ) );
                sf::Packet Packet;
                Packet.append( Data.ToConstCharArray( ), Data.size( ) );
                sf::Socket::Status status = ClientServeParams.ClientSocket->send( Packet );
                if ( status != sf::Socket::Done )
                {
                        CCL::System::IO::Console::WriteLineFmtColor( CCL::System::IO::Console::Color::RED, "[SERVER] Client % lost Connection.", { ClientServeParams.Client_ID } );
                        break;
                }
                Sleep( 1000 / 128 );
        }
#endif

        ClientServeParams.ClientSocket->disconnect( );
        delete ClientServeParams.ClientSocket;
}
 

Pages: [1]
anything