ServerFramework.NET
ServerFramework.NET copied to clipboard
An asynchronous TCP server framework written in C# for .NET 2.0 and higher.
ServerFramework.NET
ServerFramework.NET is an asynchronous, robust, open-source, extensible, and easy to use TCP server framework written in C# for .NET 2.0 and higher.
Features:
- Completely asynchronous and handles multiple clients at once
- Simple and documented code
- Easy to get running and comes with an example
- Arbitrary identification tags for clients
Changelog
v1.0: Initial version
Installation
Simply add ServerFramework.NET.dll as a reference in your .NET project and add the following line of code to the beginning of your source file.
using ServerFramework.NET;
Usage
Instantiate the Server with one of the four constructors:
var server = new Server(int port, int dataSize)
var server = new Server(int port, int dataSize, int maxNumOfClients)
var server = new Server(int port, List<char> messageDelimiters)
var server = new Server(int port, List<char> messageDelimiters, int maxNumOfClients)
Add event handlers:
server.OnMessageReceived += server_OnMessageReceived;
server.OnServerStop += (o, i) =>
{
Console.WriteLine("Server stopped");
Application.Exit();
};
static void server_OnMessageReceived(object sender, ClientEventArgs e)
{
var client = e.Client;
string msg = Encoding.ASCII.GetString(client.Message);
Console.WriteLine(msg);
client.SendData("I heard you! " + msg + "\n");
}
And start the server!
server.StartAsync();
License
This library and all associated demonstration and example programs are released under the GNU LGPL version 3. You can find a copy of this license in the file LICENSE.txt. If this file did not come with this software, the license is also online at http://gnu.org.
If you use this library, feel free to Star this repository!
Copyright (c) Souvik Banerjee 2013