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

Pages: 1 ... 5 6 [7] 8 9
91
Network / Re: Handle problems
« on: April 30, 2013, 01:26:54 am »
Where and when should I send the data(e.g. player's position) to every client?

Since you're using TCP (which I think may be a mistake since your game has real-time movement...), I suggest sending positions every .1 second. If you want to trim down on this load, I suggest using some predictions within the clients to calculate where the most probable path for movement is (games like Fun Run, a mobile game, use this method, along with many others).

-Where: in the client thread or another seperate thread(e.g. a worker thread for each client?)?

I'm not sure what you're asking here. It's possible and suggested (in my opinion and experience) that you don't multi-thread the networking components, but it's entirely possible and sometimes practical to do so. Just make sure you understand and plan out your mutexes before hand.

Also, I can't tell if you want the clients to connect with other clients instead of a server. It is possible, but it's very insecure because of the lack of security with packet and client modding.




92
SFML website / Re: New website
« on: April 30, 2013, 01:19:49 am »
I really like the new logo. Is there any chance you can upload it for promotion purposes in our games?

93
Network / Re: Sound freezes
« on: April 28, 2013, 07:01:43 pm »
This is only a dump of one way traffic. Provide the traffic in the other direction as well. It is hard to understand whether TCP is working correctly if you can only see one direction. Also provide the same for the other host (send and receive) so that you can compare both with each other and discover discrepancies.

Is this good?

http://www.mediafire.com/?27jmk41zl779lh6

94
Network / Re: Sound freezes
« on: April 28, 2013, 06:00:42 am »
I filtered and dumped everything here. After I froze, it seemed to not get any more packets on Wireshark except 4 extras which randomly came in (2 were even from UDP, which is odd).

http://www.mediafire.com/?bzjp2u7u3lumcw9

95
Network / Re: Sound freezes
« on: April 27, 2013, 07:26:53 pm »
Yeah... so after doing more digging, I don't think it's a sound problem after all since it's not even freezing apparently.

I finally reproduced the bug. Basically, the screen keep drawing but packets are failing to be received. I posted my recv() function over on the other thread... so this is kind of pissing me off. I don't know what else I can do. No packets with the error status are being reported either...

96
Network / Re: Sound freezes
« on: April 24, 2013, 12:58:33 am »
I'm not using C++11.

Quote
This is a very critical line of code. You essentially copy/move the sf::Music objects around in order to shuffle them.
His playlist variable is a container of integers.

Umm... so what do I do? What's the exact problem?

I think it may have something to do with exhausting OpenAL resources, but I'm not sure.

97
Network / Non-Blocking TCP Freeze [Fixed]
« on: April 22, 2013, 01:17:32 am »
Ok, so I've been posting my problems on this thread, which I previously believed were due to networking errors. After further investigation, I realized that the problem is rooted in the sound devices.

I've reinstalled openAL using the libraries provided with SFML, so it's not that.

Here is what Very Sleepy presents me:


If you look at the right hand side on the callstack, it appears that it freezes while playing sounds Here is another snapshot I took:


With this callstack freeze, it appears that it is trying to create a sound instead. Very odd.

Here is my SoundHandler.hpp

#ifndef __SOUNDHANDLER_HPP__
#define __SOUNDHANDLER_HPP__

#include "SFML/System.hpp"
#include "SFML/Audio.hpp"
#include <vector>

class SoundHandler
{
        private:
                sf::Clock timer;

                //////////////////////////
                //                Sounds                //
                //////////////////////////

                sf::SoundBuffer clickBuffer;
                sf::Sound clickSFX;

                sf::SoundBuffer chopBuffer;
                sf::Sound chopSFX;

                sf::SoundBuffer leavesBuffer;
                sf::Sound leavesSFX;

                sf::SoundBuffer windBuffer;
                sf::Sound windSFX;

                sf::SoundBuffer stormBuffer;
                sf::Sound stormSFX;

                sf::SoundBuffer rockBuffer;
                sf::Sound rockSFX;

                sf::Music deathSFX;

                sf::SoundBuffer blood1Buffer;
                sf::Sound blood1SFX;

                sf::Music birdSFX;

                sf::SoundBuffer killBuffer;
                sf::Sound killSFX;

                sf::SoundBuffer popBuffer;
                sf::Sound popSFX;

                sf::SoundBuffer splatBuffer;
                sf::Sound splatSFX;

                sf::SoundBuffer chargeBuffer;
                sf::Sound chargeSFX;

                sf::SoundBuffer splashBuffer;
                sf::Sound splashSFX;

                sf::SoundBuffer waterBuffer;
                sf::Sound waterSFX;

                sf::SoundBuffer fireBuffer;
                sf::Sound fireSFX;

                sf::Music cricketsSFX;

                sf::Music musicboxSFX;

                sf::Music combatSFX;

                sf::SoundBuffer typeBuffer;
                sf::Sound typeSFX;

                sf::Music feetSFX;

                sf::SoundBuffer puffBuffer;
                sf::Sound puffSFX;

                sf::SoundBuffer stabBuffer;
                sf::Sound stabSFX;

                //////////////////////////
                //                Music                 //
                //////////////////////////

                std::vector<sf::Int32> playlist;
                sf::Int32 playNumber;
                sf::Music ambient1;
                sf::Music ambient2;
                sf::Music ambient3;
                sf::Music ourHome;
                sf::Music fishing;
                sf::Music intro;
                sf::Music night;
                sf::Music main;
                bool firstPlayed;

                //      Other vars
                bool soundMuted;
                bool musicMuted;

        public:
                SoundHandler();
                void load();
                void handleMusic();
                void stopMusic();
                bool musicOn;
                void muteMusic();
                void muteSound();

                bool playClick();
                void stopClick();

                bool playWind();
                void stopWind();

                bool playChop();
                void stopChop();

                bool playLeaves();
                void stopLeaves();

                bool playStorm();
                void stopStorm();

                bool playRock();
                void stopRock();

                bool playDeath();
                void stopDeath();

                bool playBlood1();
                void stopBlood1();

                bool playBirds();
                void stopBirds();

                bool playKill();
                void stopKill();

                bool playPop();
                void stopPop();

                bool playSplat();
                void stopSplat();

                void playCharge();
                void resetCharge();

                void playFishing();
                void stopFishing();

                void playSplash();

                void playWater();

                void playCrickets();
                void stopCrickets();

                void playMain();

                void playNight();

                void playFire();

                void playMusicbox();
                void stopMusicbox();

                void playCombat();

                void playType();

                void playFeet();

                void playPuff();

                void playStab();
};

#endif
 


...and my SoundHandler.cpp

#include "stdafx.h"
#include <random>
#include <time.h>
#include "SoundHandler.hpp"
#include "Globals.hpp"

SoundHandler::SoundHandler()
{
        load();
        musicMuted = false;
        soundMuted = false;
}

void SoundHandler::load()
{
        //////////////////////////
        //                Sounds                //
        //////////////////////////

        clickBuffer.loadFromFile("rsc/SFX/click.ogg");
        clickSFX.setBuffer(clickBuffer);

        chopBuffer.loadFromFile("rsc/SFX/chop.ogg");
        chopSFX.setBuffer(chopBuffer);

        leavesBuffer.loadFromFile("rsc/SFX/leaves.ogg");
        leavesSFX.setBuffer(leavesBuffer);

        windBuffer.loadFromFile("rsc/SFX/wind.ogg");
        windSFX.setBuffer(windBuffer);
        windSFX.setLoop(true);

        stormBuffer.loadFromFile("rsc/SFX/storm.ogg");
        stormSFX.setBuffer(stormBuffer);

        rockBuffer.loadFromFile("rsc/SFX/rock.ogg");
        rockSFX.setBuffer(rockBuffer);

        deathSFX.openFromFile("rsc/SFX/death.ogg");

        blood1Buffer.loadFromFile("rsc/SFX/blood1.ogg");
        blood1SFX.setBuffer(blood1Buffer);

        birdSFX.openFromFile("rsc/SFX/birds.ogg");

        killBuffer.loadFromFile("rsc/SFX/kill.ogg");
        killSFX.setBuffer(killBuffer);

        popBuffer.loadFromFile("rsc/SFX/pop.ogg");
        popSFX.setBuffer(popBuffer);

        splatBuffer.loadFromFile("rsc/SFX/splat.ogg");
        splatSFX.setBuffer(splatBuffer);

        chargeBuffer.loadFromFile("rsc/SFX/charge.ogg");
        chargeSFX.setBuffer(chargeBuffer);
        resetCharge();

        splashBuffer.loadFromFile("rsc/SFX/splash.ogg");
        splashSFX.setBuffer(splashBuffer);

        waterBuffer.loadFromFile("rsc/SFX/water.ogg");
        waterSFX.setBuffer(waterBuffer);
        waterSFX.setVolume(25);

        cricketsSFX.openFromFile("rsc/SFX/crickets.ogg");

        fireBuffer.loadFromFile("rsc/SFX/fire.ogg");
        fireSFX.setBuffer(fireBuffer);

        musicboxSFX.openFromFile("rsc/SFX/musicbox.ogg");
        musicboxSFX.setLoop(true);

        combatSFX.openFromFile("rsc/SFX/combat.ogg");

        typeBuffer.loadFromFile("rsc/SFX/type.ogg");
        typeSFX.setBuffer(typeBuffer);

        feetSFX.openFromFile("rsc/SFX/feet.ogg");

        puffBuffer.loadFromFile("rsc/SFX/puff.ogg");
        puffSFX.setBuffer(puffBuffer);

        stabBuffer.loadFromFile("rsc/SFX/stab.ogg");
        stabSFX.setBuffer(stabBuffer);

        //////////////////////////
        //                Music                 //
        //////////////////////////

        //      Day Playlist
        ourHome.openFromFile("rsc/Music/ourHome.ogg");                  //      0
        playlist.push_back(0);
        ambient1.openFromFile("rsc/Music/ambience1.ogg");               //      1
        playlist.push_back(1);
        ambient2.openFromFile("rsc/Music/ambience2.ogg");               //      2
        playlist.push_back(2); 
        night.openFromFile("rsc/Music/night.ogg");                              //      3
        playlist.push_back(3);
        ambient3.openFromFile("rsc/Music/ambience3.ogg");               //      4
        playlist.push_back(4);

        musicOn = true;
        firstPlayed = false;
        srand(time(NULL));
        std::random_shuffle(playlist.begin(), playlist.end());
        playNumber = 0;

        //      Fishing
        fishing.openFromFile("rsc/Music/fishing.ogg");
        fishing.setLoop(true);

        //      Intro
        intro.openFromFile("rsc/Music/intro.ogg");
        intro.setLoop(true);

        //      Main
        main.openFromFile("rsc/Music/The Colony.ogg");
        main.setLoop(true);
}

void SoundHandler::handleMusic()
{
        if(((timer.getElapsedTime().asSeconds() >= 300) || ((!firstPlayed) && (timer.getElapsedTime().asSeconds() >= 60))) && musicOn && !musicMuted)
        {
                firstPlayed = true;
                sf::Int32 songNumber = playlist[playNumber];
                bool restartTimer = true;

                if(songNumber == 0)
                {
                        ourHome.play();
                }

                else if(songNumber == 1)
                {
                        ambient1.play();
                }

                else if(songNumber == 2)
                {
                        ambient2.play();
                }

                else if((songNumber == 3))
                {
                        if((gl::Vars::timeOfDay == NIGHT) || (gl::Vars::timeOfDay == DAWN) || (gl::Vars::timeOfDay == DAWN))
                                night.play();
                        else
                                restartTimer = false;
                }

                else if((songNumber == 4))
                {
                        ambient3.play();
                }

                if(restartTimer)
                        timer.restart();

                playNumber++;
                if(playNumber >= playlist.size())
                {
                        srand(time(NULL));
                        std::random_shuffle(playlist.begin(), playlist.end());
                        playNumber = 0;
                }
        }

        else if(timer.getElapsedTime().asSeconds() >= 300)
        {
                timer.restart();
        }
}

void SoundHandler::stopMusic()
{
        ourHome.stop();
        ambient1.stop();
        ambient2.stop();
        ambient3.stop();
        fishing.stop();
        intro.stop();
        night.stop();
        musicboxSFX.stop();
        main.stop();
}

void SoundHandler::muteMusic()
{
        musicMuted = !musicMuted;

        if(!musicMuted)
                stopMusic();
}

void SoundHandler::muteSound()
{
        soundMuted = !soundMuted;
        windSFX.stop();
        feetSFX.stop();
        cricketsSFX.stop();
        birdSFX.stop();
}

bool SoundHandler::playChop()
{
        if(!soundMuted)
                chopSFX.play();
        return true;
}

void SoundHandler::stopChop()
{
        chopSFX.stop();
}

bool SoundHandler::playClick()
{
        if(!soundMuted)
                clickSFX.play();
        return true;
}

void SoundHandler::stopClick()
{
        clickSFX.stop();
}

bool SoundHandler::playLeaves()
{
        if(!soundMuted)
                leavesSFX.play();
        return true;
}

void SoundHandler::stopLeaves()
{
        leavesSFX.stop();
}

bool SoundHandler::playWind()
{
        if(!soundMuted)
                windSFX.play();
        return true;
}

void SoundHandler::stopWind()
{
        windSFX.stop();
}

bool SoundHandler::playStorm()
{
        if(!soundMuted)
                stormSFX.play();
        return true;
}

void SoundHandler::stopStorm()
{
        stormSFX.stop();
}

bool SoundHandler::playRock()
{
        if(!soundMuted)
                rockSFX.play();
        return true;
}

void SoundHandler::stopRock()
{
        rockSFX.stop();
}

bool SoundHandler::playDeath()
{
        if(!musicMuted)
                deathSFX.play();
        return true;
}

void SoundHandler::stopDeath()
{
        deathSFX.stop();
}

bool SoundHandler::playBlood1()
{
        if(!soundMuted)
                blood1SFX.play();
        return true;
}

void SoundHandler::stopBlood1()
{
        blood1SFX.stop();
}

bool SoundHandler::playBirds()
{
        if(!soundMuted)
                birdSFX.play();
        return true;
}

void SoundHandler::stopBirds()
{
        birdSFX.stop();
}

bool SoundHandler::playKill()
{
        if(!soundMuted)
                killSFX.play();
        return true;
}

void SoundHandler::stopKill()
{
        killSFX.stop();
}

bool SoundHandler::playPop()
{
        if(!soundMuted)
                popSFX.play();
        return true;
}

void SoundHandler::stopPop()
{
        popSFX.stop();
}

bool SoundHandler::playSplat()
{
        if(!soundMuted)
                splatSFX.play();
        return true;
}

void SoundHandler::stopSplat()
{
        splatSFX.stop();
}

void SoundHandler::playCharge()
{
        if(!soundMuted)
                chargeSFX.play();
        chargeSFX.setPitch(chargeSFX.getPitch() + .1);
}

void SoundHandler::resetCharge()
{
        chargeSFX.setPitch(.1);
}

void SoundHandler::playFishing()
{
        if(!musicMuted)
                fishing.play();
}

void SoundHandler::stopFishing()
{
        fishing.stop();
}

void SoundHandler::playSplash()
{
        if(!soundMuted)
                splashSFX.play();
}

void SoundHandler::playWater()
{
        waterSFX.setPitch((rand() % 20) * .1 + .1);
        if(!soundMuted)
                waterSFX.play();
}

void SoundHandler::playCrickets()
{
        if(!soundMuted)
                cricketsSFX.play();
}

void SoundHandler::stopCrickets()
{
        if(!soundMuted)
                cricketsSFX.stop();
}

void SoundHandler::playMain()
{
        if(!musicMuted)
                main.play();
}

void SoundHandler::playNight()
{
        if(!soundMuted)
                night.play();
}

void SoundHandler::playFire()
{
        if(!soundMuted)
                fireSFX.play();
}

void SoundHandler::playMusicbox()
{
        musicOn = false;
        stopMusic();
        musicboxSFX.stop();
        if(!soundMuted && !musicMuted)
        {
                musicboxSFX.play();
                stabSFX.play();
        }
}

void SoundHandler::stopMusicbox()
{
        musicboxSFX.stop();
}

void SoundHandler::playCombat()
{
        if(!soundMuted)
                combatSFX.play();
}

void SoundHandler::playType()
{
        if(!soundMuted)
                typeSFX.play();
}

void SoundHandler::playFeet()
{
        if(!soundMuted)
                feetSFX.play();
}

void SoundHandler::playPuff()
{
        if(!soundMuted)
                puffSFX.play();
}

void SoundHandler::playStab()
{
        if(!soundMuted)
                stabSFX.play();
}
 

For the sake of "minimal and complete examples", here is an example main function:
#include "SoundHandler.hpp"

int main()
{
        SoundHandler soundHandler;
        soundHandler.load();
        soundHandler.handleMusic();
        soundHandler.playCombat();

        return 0;
}
 

Of course, this probably will not crash it since it crashes randomly when I play sounds. I haven't been able to solidly reproduce it yet repeatedly, so I apologize for lack of information.

My guess is that it may have to do with music being loaded at the same time as sounds? That's just a guess from my debugging, but I can't be sure.

All of the sounds are <1 second and the music is anywhere from 30 secs to 5 minutes.

Also, this occasionally gets output in my console and in other's:


Any ideas?

98
Network / Re: Non-Blocking TCP Crashing Client?
« on: April 21, 2013, 12:06:48 am »
Ok, while I'm waiting for that error to reproduce, do you think it has to do with sounds and audio? This error randomly happens as well:


This is all leading me to believe that sounds have something to do with it. I'm pretty sure sounds use multiple threads, so that would explain the freezes. This error happens randomly, even to me.

One of my testers also reported this:


If you look over on the callstack (right hand side), it appears that there were some other SFML functions being called, but without any of my functions. This leads me to believe that it has to do with sounds even more.

Do sounds operate on different threads than the main loop? I assume so.

Edit:
I have confirmed that it has to do with sounds. Closing this thread and starting a new one in the sound board. Thanks.

Thread is here:
http://en.sfml-dev.org/forums/index.php?topic=11235.msg77784#msg77784

99
Network / Re: Non-Blocking TCP Crashing Client?
« on: April 20, 2013, 09:46:18 pm »
The WaitForMultipleObjects entry in Sleepy also hints at the usage of a Mutex lock that might be causing the freezing in the client. So maybe you might want to investigate those and see which one locks indefinitely, for example by outputing all the locks and unlocks to a log.txt for debug purposes and having your testers send those to you.

Well that's the thing-- I'm not using any mutexes at all. All the connection thread does is connect(), so I didn't see a point.

100
Network / Re: Non-Blocking TCP Crashing Client?
« on: April 20, 2013, 08:32:45 pm »
Ok, I'll try some of those methods later.

Apparently, the crashes are actually freezes. I had one of my testers use Very Sleepy to track the processes of the threads and this is what he got:


This is the exact same info and process that it was stuck on with the server before I switched to non-blocking. Oddly enough, non-blocking on the client doesn't do anything about it. I've narrowed the whole program down to two threads (connecting and main) and that's what always happens. It may also have something to do with sounds, although I doubt it.

By the way, this has been happening ever since I switched the server networking to non-blocking, which seems very odd.

101
Network / Non-Blocking TCP Crashing Client?
« on: April 20, 2013, 02:58:59 am »
Overview
Ok, sorry to bug you guys and make a new thread, but I feel that the other one was titled wrongly for what I' now encountering.

The server is now stable thanks to Binary's help, but my client is very unstable. Again, I cannot replicate any of the crashes myself, which leads me to believe that people who live further away (with greater ping times) are corrupting the packets somehow. I don't know how this is possible, but it's crippling the stability of my playerbase and I have absolutely no way of testing it.

Details:
I am using unblocking TCP sockets, although I switch to blocking when I connect() from the client.

Code

Server send code:
void NetworkManager::sendPacket(sf::Packet* pack, sf::Int32 connectorID, bool delPacket)
{
        if(getConnectorWithID(connectorID) != NULL)
        {
                Connector* c = getConnectorWithID(connectorID);
                if(c != NULL)
                        c->sendPacket(pack);
        }

        if(delPacket)
        {
                //sf::Int32 packID;
                //*pack >> packID;
                //std::cout << "Sending :: " << packID << "\n";

                delete pack;
        }
}
 


Retry send if it fails or returns sf::Socket::NotReady:
void NetworkManager::retryDroppedPackets()
{
        for(sf::Int32 i = 0; i < ent::connectors.size(); i++)
        {
                if(ent::connectors[i]->packets.size() > 0)
                {
                        sf::Socket::Status status = ent::connectors[i]->socket.send(ent::connectors[i]->packets.front());

                        if(status != sf::Socket::NotReady && status != sf::Socket::Error)
                        {
                                ent::connectors[i]->packets.pop();

                                if(status == sf::Socket::Error)
                                {
                                        std::cout << "E1E\n";
                                }
                        }
                }
        }
}
 


Server receive code:
void NetworkManager::recPackets()
{
        Connector* newConnector = new Connector;
        newConnector->socket.setBlocking(false);
        newConnector->player = NULL;

        if(listener.accept(newConnector->socket) == sf::Socket::Done)
        {
                //      Adds a new client to client list
                maxConID += 1;
                newConnector->setID(maxConID);
                ent::connectors.push_back(newConnector);
        }

        else
        {
                //      Nothing we can do...
                delete newConnector;
        }


        //      The listener socket is not ready, test all other sockets
        for(sf::Int32 i = 0; i < ent::connectors.size(); i++)
        {
                sf::Packet packet;
                sf::Socket::Status status = ent::connectors[i]->socket.receive(packet);

                if(status == sf::Socket::Done)
                {
                        ent::connectors[i]->logClock.restart();

                        sf::Uint32 packetCode;
                        packet >> packetCode;

                        handlePacket(packetCode, packet, ent::connectors[i]->getID());
                }

                else if(status == sf::Socket::Disconnected)
                {
                        ent::playerHandler.handleDisconnect(ent::connectors[i]->getID());
                }

                else if(status == sf::Socket::Error)
                {
                        std::cout << "NetworkingError";
                }

                else if(status == sf::Socket::NotReady)
                {
                        //      Not ready
                        //std::cout << "not ready";
                }
        }
}
 


Client send code:
void NetworkManager::sendPacket(sf::Packet* pack)
{
        socket.setBlocking(false);
        if(droppedPackets.size() <= 0)
        {
                sf::Socket::Status status = socket.send(*pack);

                if(status == sf::Socket::Done)
                {
                        delete pack;
                }

                else if(status == sf::Socket::NotReady)
                {
                        droppedPackets.push(pack);
                }

                else if(status == sf::Socket::Error)
                {
                        std::cout << "ERROR";
                        droppedPackets.push(pack);
                }

                else if(status == sf::Socket::Disconnected)
                {
                        if(ent::game.isRunning())
                        {
                                ent::game.disconnect();
                                delete pack;
                        }
                }
        }

        else
        {
                droppedPackets.push(pack);
        }
}
 


Server send code if first time fails:
void NetworkManager::retryPackets()
{
        if(droppedPackets.size() > 0)
        {
                socket.setBlocking(false);
                sf::Socket::Status status = socket.send(*droppedPackets.front());

                if(status == sf::Socket::Done)
                {
                        delete droppedPackets.front();
                        droppedPackets.pop();
                }

                else if(status == sf::Socket::NotReady)
                {
                        //      Do nothing

                }

                else if(status == sf::Socket::Error)
                {
                        std::cout << "ERROR";
                        delete droppedPackets.front();
                        droppedPackets.pop();
                }

                else if(status == sf::Socket::Disconnected)
                {
                        if(ent::game.isRunning())
                        {
                                ent::game.disconnect();
                                delete droppedPackets.front();
                                droppedPackets.pop();
                        }
                }
        }
}
 


Client receive:
void NetworkManager::handle()
{
        retryPackets();

        socket.setBlocking(false);

        sf::Packet pack;
        sf::Socket::Status status = socket.receive(pack);

        if(status == sf::Socket::Done)
        {
                sf::Int32 packetType;           //      Determines what the packet contains, different packet types contain different info

                if(pack >> packetType)
                {
                        if(displayPacketID)
                                std::cout << "\nPacket Type :: " << packetType;
//
//
//                    Handle Packet
//
//

}

                else
                {
                        if(displayPacketID)
                                std::cout << "Junk Packet";
                }
        }

        else
        {
                //      not ready
        }
}
 


Client connect code (runs on its own thread):
bool NetworkManager::connect(std::string IP, sf::Int32 port)
{
        if(ip != NULL)
                delete ip;

        ip = new sf::IpAddress(IP);

        socket.setBlocking(true);
        sf::Socket::Status status = socket.connect(*ip, port, sf::milliseconds(250));
        socket.setBlocking(false);

        if(status == sf::Socket::Disconnected)
        {
                //std::cout << "disconnected";
                connected = false;
                gl::Vars::connected = false;
                return false;
        }

        else if(status == sf::Socket::Done)
        {

                //std::cout << "connected";
                gl::Vars::connected = true;
                connected = true;

                sf::Packet* spack = new sf::Packet;
                sf::Int32 packID = 0;
                *spack << packID << gl::Vars::versionNumber;
                ent::networkManager.sendPacket(spack);

                return true;
        }

        else if(status == sf::Socket::Error)
        {
                connected = false;
                gl::Vars::connected = false;

                return false;
        }

        else
        {
                std::cout << "not ready";
                connected = false;
                gl::Vars::connected = false;

                return false;
        }
}


Client Main:
ent::menu.Run();

        if(ent::menu.getSuccess())      //      If logged in
        {
                ent::loadingScreen.Run();
                if(ent::game.Run())             //      if dead
                {
                        ent::death.Run();
                }
        }


Game.Run()
Init();
        cleanClock.restart();
        while(running && !dead)
        {
                ent::networkManager.handle();
                Input();
                Data();
                Clear();
                Draw();
                if(cleanClock.getElapsedTime().asSeconds() >= 10.0f)
                {
                        cleanClock.restart();
                        Clean();
                }
        }
        cleanUp();

        return dead;


I'd love if one of you veterans could add me on Skype (brady.welch) so we can resolve this issue. I could send you the full source and client for you to test for my game.

102
Network / Re: TCP Lag Reduction Techniques?
« on: April 13, 2013, 01:22:49 am »
Yeah, people are still getting deformed packets. I still can't test them since it only happens with people who have bad connections. The client nor the server is returning any errors on receive.

EDIT:
It seems to be because the client is now getting deadlocked. Is it even possible to have a single threaded client with a loading screen and all?

Client send code:
void NetworkManager::sendPacket(sf::Packet* pack)
{
        if(gl::Vars::connected)
        {
                socket.send(*pack);
                delete pack;
        }
}
 

103
Network / Re: TCP Lag Reduction Techniques?
« on: April 12, 2013, 04:34:59 am »
Check if sf::Socket::Error is returned. If you are indeed getting socket errors, you can check what kind of errors you are getting using the operating system specific function WSAGetLastError() in Windows or checking errno in Linux.

Oh ok. Thank you! I think it was actually a client issue, because after I switched that client recv() function around, nobody has crashed yet (I have my fingers crossed).

104
Network / Re: TCP Lag Reduction Techniques?
« on: April 12, 2013, 02:52:32 am »
You should handle the case that send() returns sf::Socket::Error as well. TCP does not complain about little things that can be corrected over time so whenever an error really occurs you should take it seriously and try to resolve it.

How do I "resolve it" exactly?

105
Network / Re: TCP Lag Reduction Techniques?
« on: April 11, 2013, 01:46:30 am »
What do you mean by "corrupts the packets"? If you mean data corruption, how do you determine this? Did you check whether this corresponds to what the server is sending?

As for the receive not working, it might also be the client code that is not sending/functioning properly. If you want to make robust software that functions even over bad connections, you need to make sure that both sides are able to handle such a scenario.

Maybe you could show the client send and receive code as well.

Ok. Here is the client receive code (it is multi threaded and blocking still since I haven't had any problems with it).

while(running)
        {
                while(gl::Vars::connected)
                {
                        sf::Packet pack;
                        socket.receive(pack);

                        gl::mutex.lock();
                        sf::Int32 packetType;           //      Determines what the packet contains, different packet types contain different info

                        if(pack >> packetType)
                        {
                                       /*
                                                      HANDLE PACKETS

                                        */

            }

                        else
                        {
                                std::cout << "Junk Packet";
                        }

                        gl::mutex.unlock();
                        sf::sleep(sf::milliseconds(10));
                }
                sf::sleep(sf::seconds(.1));
        }
}
 

I really don't think this is a client sided issue since it was receiving the packets correctly before I changed it all around.

By the way, I also simplified the server sends:
void Connector::sendPacket(sf::Packet* spack)
{
        if(packets.size() <= 0)
        {
                sf::Socket::Status status = socket.send(*spack);

                if(status == sf::Socket::NotReady)
                {
                        packets.push(*spack);
                }
        }

        else
        {
                packets.push(*spack);
        }
}
 

void NetworkManager::retryDroppedPackets()
{
        for(sf::Int32 i = 0; i < ent::connectors.size(); i++)
        {
                if(ent::connectors[i]->packets.size() > 0)
                {
                        sf::Socket::Status status = ent::connectors[i]->socket.send(ent::connectors[i]->packets.front());

                        if(status != sf::Socket::NotReady)
                        {
                                ent::connectors[i]->packets.pop();
                        }
                }
        }
}
 

Pages: 1 ... 5 6 [7] 8 9
anything