The motivation behind NetworkComms.Net was to create a fully featured C# network library with which network functionality could be easily added to any application, from .net 2 up to .net 4.5 (Mono, Unity3d, iOS, Android, WinRT/Windows Store and Windows Phone 8 also supported). We also wanted to require little to no knowledge of networking to make things work first time, alongside all of the desirable power features for more experienced network developers. We created two tutorials, in C#, How To Create A Client Server Application In Minutes and Creating A WPF Chat Client Server Application to demonstrate the most basic features of this C# network library. Please see our other library tutorials here.
Using our network library you can send any custom object via TCP or UDP using IPv4 or IPv6 across multiple platforms in just a single line of code. Having said that there are also much more powerful methods/features available (click here for a full feature list):
//There are loads of ways of sending data //The most simple, which we use here, just uses an //IP address (string) and port (integer) //We are going to be sending a string object NetworkComms.SendObject("Message", "127.0.0.1", 10000, "Networking in one line!");
To receive:
//We need to define what happens when packets are received. //To do this we add an incoming packet handler for //a 'Message' packet type. // //We will define what we want the handler to do inline by using //a lambda expression //http://msdn.microsoft.com/en-us/library/bb397687.aspx. //We could also just point AppendGlobalIncomingPacketHandler //to a standard method (See other networkcomms.net examples) // //This handler will convert the incoming raw bytes into a string //(this is what the <string> bit does) and then write that //string to the local console window. NetworkComms.AppendGlobalIncomingPacketHandler<string>("Message", (packetHeader, connection, incomingString) => { Console.WriteLine("\n ... Incoming message from " + connection.ToString() + " saying '" + incomingString + "'."); }); //Start listening for incoming 'TCP' connections. The true //parameter means try to use the default port and if that //fails just choose a random port. //See also ConnectionType.UDP and ConnectionType.Bluetooth Connection.StartListening(ConnectionType.TCP, IPEndPoint(IPAddress.Any, 0));
NetworkComms.Net is written in C# and can be downloaded here. Currently most examples and code snippets are given in C# but we endeavour to extend this to other .net languages in the near future.