Network library is a simple C# Network Library that takes the complication of managing a TCP/IP connections and includes many handy features.
Network comes with the follow features:
- Simple and easy to use.
- Events.
- Native serializing support.
- Object registration.
- Support bind-able objects.
- And lots more...
When using Network Library, both the client and server share the
same interface INetwork. As such, you can keep the core code
almost the same, whether you're dealing with the server or the
client.
Creating a server is very simple. Create an instance of
ConnectionHost and run StartBroadcasting:
usingSystem;usingNetworkLibrary.Core;publicclassMainProgram{staticINetworktheConnection;publicstaticvoidMain(paramsstring[]args){//Create an instance of our host.theConnection=newConnectionHost(33050);//Run the listener.(theConnectionasConnectionHost).StartBroadcasting();Console.WriteLine("\nHost up and running. Press any key to quit.");//Prevent the program from closingConsole.ReadKey();}}Creating a client is also simple:
usingSystem;usingNetworkLibrary.Core;publicclassMainProgram{staticINetworktheConnection;publicstaticvoidMain(paramsstring[]args){//Create an instance of our host.theConnection=newConnectionClient();//Connect to server.(theConnectionasConnectionClient).Connect("127.0.0.1",33050);Console.WriteLine("\nSucessfully connected. Press any key to quit.");//Prevent the program from closingConsole.ReadKey();}}Sending events is also very easy. Just register a function with specific integer code:
intcode=0;//Code for this eventourNetworkConnection.RegisterEvent(code,eventThatShouldBeRun);/* ... */privatevoideventThatShouldBeRun(objectsource,NetworkEventArgsargs){Console.WriteLine(sourceasstring);}After that, you can easily send this type of message by simply doing:
intcode=0;//Code for this eventconnection.SendEvent(code,"Hello World");For more information, check out Establish Connection and Registering events.
Full documentation on Network Library can be found on the wiki.
Network Library is licensed under the terms of the WTFPL, see the included LICENSE file.