About | Rules and Guide | Sign In/Create Account | Write a Post
Construction1990’s Internet Montage? No!
Please excuse the site weirdness. Mike is fixing and making things.
Ludum Dare 31 — Coming December 5th-8th 2014!

  • ??? Begins: in 9 days, 10 hours, 15 minutes, 44 seconds
  • October Ends: in 10 days, 10 hours, 27 minutes, 44 seconds
  • Ludum Dare 31 begins: in 45 days, 11 hours, 15 minutes, 44 seconds
  • (FYI: Clock might be off) | Ludum Dare 31: Real World Gatherings (Now Open!)

    [ October Challenge 2014 | Resources | Submit/Edit | View All ]

    Posts Tagged ‘GNI’

    Presenting Generic Netplay Implementation, an experimental and possibly buggy C# network library

    Posted by (twitter: @VDZ)
    Monday, April 16th, 2012 2:05 pm

    I probably won’t use this next weekend, but I’m posting this just in case I do want to use it.
    GNI is a library to facilitate some simple, easy to use communication between a server and any number of clients.
    Please note that this was coded in a relatively short time span, it was not tested extensively, network code is vulnerable to tons of unpredictable bugs, and my experience with netplay development is limited.
    What I want to say is, don’t rely on it unless you’re capable of fixing bugs in it, as it might break at the worst possible moment.
    The example chat program I wrote seems to work perfectly, though, so it should work. ‘Should’ being the key word here.

    -Simple way to send signals from server to client and vice versa, without bothering with minor technical details
    -Automatically calls a function when a signal is received, a player connects, or a player disconnects

    Code includes a simple chat server project and chat client project as examples.

    DLL download link (5 KB)
    Source download link with example (19 KB) (Microsoft Visual Studio 2010 solution)

    How it works
    Small packages of information called GNIDatas are sent through the library. When received, it’s reconstructed as a GNIData struct.
    GNIData consists of a key-value pair, with the keys or values being shorts (16-byte integers), strings, or nothing.

    -The server class must inherit from the library’s GNIServer class.
    -Call StartServer(…) to start the server. You can have it check for incoming signals automatically, or choose to do so manually by calling Update().
    -Override OnDataReceived(GNIData data, uint source) to interpret signals. It’s called from Update when a full GNIData has been received. ‘Source’ is the clientID of the client that sent the signal.
    -Override OnClientConnected(GNIClientInformation client) if you want something to happen when a player joins. (The client is automatically added to the client list.)
    -Override OnClientDisconnected(GNIClientInformation client) if you want something to happen when a player disconnects. (The client is automatically removed from the client list.)
    -Use SendSignal(…) to send a GNIData to a client, or BroadcastSignal(…) to send a GNIData to every client.
    -Send empty signals (datatype and valuetype ‘none’) if you want the server to automatically detect if a connection has been lost; otherwise it won’t notice until it fails to send a signal to it.

    -The client class must inherit from the library’s GNIClient class.
    -Call StartClient(…) to start the client. It WILL NOT check for incoming signals automatically; call AutoPoll() to have it do that. Alternatively, call Update() whenever you want to check for incoming signals.
    -Override OnDataReceived(GNIData data, uint source) to interpret signals. It’s called from Update when a full GNIData has been received. ‘Source’ is always 0 and meaningless in the client.
    -Use SendSignal(…) to send a GNIData to the server.
    -To be honest, I’m not sure what happens when the client unexpectedly loses connection to the server. It’ll probably throw an exception, so just catch that.

    Does not exist. If you can’t figure out the code, it’s best not to use it as it might still be buggy.

    This work is licensed under a Creative Commons Attribution 3.0 Unported License.
    You are free:
    * to Share β€” to copy, distribute and transmit the work
    * to Remix β€” to adapt the work
    * to make commercial use of the work
    Under the following conditions:
    * Attribution β€” You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

    Have fun, and good luck with your games.

    All posts, images, and comments are owned by their creators.

    [cache: storing page]