A small network lib

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

A small network lib

Post by sudi »

I recently started coding on my gameengine again and remade some of the network. Well after fitting the network engine for my needsi thought hey why not make my own networkengine. So i stated coding and made this little thing. Right now its just tcp but i guess i will add udp after adding all needed stuff.

Its of course non blocking. Just call INetwork::receive once a frame and it will return all messages received until then.

Download

Example:

Server

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include "INetwork.h"

int main(int argc, char* argv[])
{
    AppFrame::INetwork* network = AppFrame::createNetwork("Sudi", 80, 2, 2, "none");
    if (network->Error())
        return 1;

    while(1)
    {
        AppFrame::array<AppFrame::NetworkPacket*> p = network->receive();
        printf("Receive %i packets\n", p.size());
        for(AppFrame::u32 i=0;i<p.size();i++)
        {
            printf("Receiving: %i\n", p[i]->Packet_ID);
            p[i]->drop();
        }
        printf("run\n");
    }

    printf("done\n");
    system("pause");
    return 0;
}
Client

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include "INetwork.h"
#include "appArray.h"

int main(int argc, char* argv[])
{
    AppFrame::INetwork* network = AppFrame::createNetwork("Sudi", 500, 1, 0, "none");
    if (network->Error())
        return 1;

    if (network->connect2Peer("localhost", 80))
    {
        printf("connected\n");
    }
    while(1)
    {
        AppFrame::array<AppFrame::NetworkPacket*> p = network->receive();
        printf("Receive %i packets\n", p.size());
        for(AppFrame::u32 i=0;i<p.size();i++)
        {
            printf("Receiving: %i\n", p[i]->Packet_ID);
            p[i]->drop();
        }
    }

    delete network;
    printf("done\n");
    system("pause");
    return 0;
}
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Out of interest, why roll your own network engine when Enet, IrrNet and Raknet are all available and do more?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

learning i guess
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

rogerborg wrote:Out of interest, why roll your own network engine when Enet, IrrNet and Raknet are all available and do more?
Well I just wanted to see if i can pull it of...Thats it.

And since it is tcp i will intgrate some irc functions and then use it as chat ystem in my gameengine.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

do yourself a favor and activate TCP_NODELAY if you want to use tcp for timecritical actions. It handles with the delayedack/nagle issue.
Post Reply