GPWiki.org
GPWiki.org
It is currently Tue May 21, 2013 6:46 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Lidgren?
PostPosted: Fri Nov 11, 2011 4:15 am 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
Is anyone having any success with the Lidgren Networking Library?

The tutorials are absolutely horrible/incomplete/inconsistant/broken.. the samples don't compile properly, and are old and outdated. The samples on his site leave ALOT of key things unexplained.

The library seems good(there seem to be people out there having success with it), but the documentation is basically worthless; I'm not using VS 2008 and the 2010 'conversion' process doesn't seem to pull it off properly.

Absolutely *none* of the "working examples" compile for me.(yeah ive referenced the dll).

Ive got a server up and running (i think? no way to be sure since the client cant seem to find it. I think?). Thats about as far as I got.

Anyone know of a good *up to date/working* step by step?

Thanks!

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
 Post subject: Re: Lidgren?
PostPosted: Fri Nov 11, 2011 10:14 am 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
I feel your pain man, but haven't use lidgren at all.

You might be hoping for too much in getting a 2008 project to run straight up without doing some changes to the project settings first.

Is the code compiling and segfaulting, or not compiling at all? If you've got compile troubles, you need to start triple checking your library and include paths and whatever library compiler flags you might need.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
 Post subject: Re: Lidgren?
PostPosted: Fri Nov 11, 2011 12:55 pm 
King Code Monkey
User avatar

Joined: Wed Sep 01, 2004 3:05 pm
Posts: 11182
Location: Abingdon, MD
I was about to get the sample working with no problems in VS 2010. Do you have something you can upload somewhere so we can see what's going on?

_________________
Bored? Head on over to my blog and see what I'm up to.

Microsoft XNA MVP


Top
 Profile  
 
 Post subject: Re: Lidgren?
PostPosted: Fri Nov 11, 2011 10:56 pm 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
SERVER:


Code:
namespace TankzLidgrenServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {




        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (txtInput.Text != "")
            {
                txtServerOutput.Text += "\n " + txtInput.Text;
                txtInput.Text = "";
            }
        }

        private void btnCloseServer_Click(object sender, EventArgs e)
        {
           
        }

        private void btnStartServer_Click(object sender, EventArgs e)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("Tankz");
            config.Port = 14242;
            NetServer server = new NetServer(config);
            server.Start();
            txtServerOutput.Text += "\nServer Started.";

            config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);

            NetIncomingMessage msg;
            while ((msg = server.ReadMessage()) != null)
            {
                switch (msg.MessageType)
                {
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.ErrorMessage:
                       
                        txtServerOutput.Text += "\n" + msg.ReadString();
                        break;

                    case NetIncomingMessageType.DiscoveryRequest:

                        NetOutgoingMessage response = server.CreateMessage();
                        response.Write("Tankz Server 0.0.1");
                        txtServerOutput.Text += "\n" + "Client Connected from " + msg.SenderEndpoint;

                        server.SendDiscoveryResponse(response, msg.SenderEndpoint);
                        break;


                    default:
                    txtServerOutput.Text += "\n" + "Unhandled type: " + msg.MessageType;
                        break;
                }
                server.Recycle(msg);
            }
        }
    }
}


Now the server seems to work. When I first ran it, Windows informed me that it was trying to access the internet. That's good.

The client on the other hand..

CLIENT:

Code:
namespace LidgrenClientTest
{
    public partial class frmClientTest : Form
    {
        public frmClientTest()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("Tankz");
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);

            NetClient client = new NetClient(config);
            client.Start();

            client.DiscoverKnownPeer("localhost", 14242); //These two lines.. I've tried DicoverLocalPeers, I've tried using the loopback IP as the IP,
            client.Connect("localhost", 14242 );          //...the server says its binding a socket to O.O.O.O, so ive even tried that as the IP.. no luck.
                                                          //the server has no code to handle incoming messages just yet, but it should at very least indicate
                                                          //that a client has made an attempt to discover.. but it doesnt.

           NetOutgoingMessage sendMsg = client.CreateMessage();
           sendMsg.Write("Hello");
           sendMsg.Write(42);
           
            NetIncomingMessage inc;

            while ((inc = client.ReadMessage()) != null)
            {
                switch (inc.MessageType)
                {
                    case NetIncomingMessageType.DiscoveryResponse:
                        txtOutput.Text += "Found server at " + inc.SenderEndpoint + " name: " + inc.ReadString();
                        break;
                }
            }
        }
    }
}



So for now, as far as I can tell, the Client is not discovering the server... or at least the server isn't reacting to the discovery request the way it should.

This is the first time I've posted actual code on this site, looking for help. It feels very dirty. Ugh. (then again, with Lidgren im using someone elses code under the hood of my game, which also feels dirty.. what the heck, right?)

EDIT: Since posting this, ive noticed something. In the server code, I moved the:

config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);

line ABOVE where the config is used to initialize the server. Makes sense. But didn't help any. lol.

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group