Resource Page DescriptionAsynchronous Servers created using C# and XF.Server API. Network events are processed using I/O completion port.
XF.Server Network API Examples
This simple examples demonstrates the power of network API which helps to creates IOCP Server just in seconds. Simple Asynchronous C# Server Example
using System;
using System.Net;
using System.Text;
using XF;
namespace Demo
{
class Program
{
static void Main()
{
using (var listener =
Network.AcceptAsync(
new IPEndPoint(IPAddress.Any, 80),
connection => connection.ReadAsync((ignore, buffer, bytesReceived) =>
{
connection.Close(); //data received, close connection
Console.WriteLine(Encoding.ASCII.GetString(buffer.Data, buffer.Offset, bytesReceived));
})))
{
Console.WriteLine("XF.Server is ready to accept connections at {0}.", listener.EndPoint);
Console.WriteLine("Press any key to exit.");
Console.ReadKey(true);
}
}
}
}
Asynchronous C# Echo Server Example
using System;
using System.Net;
using XF;
namespace Demo
{
class Program
{
static void Main()
{
using (var listener =
Network.AcceptAsync(
new IPEndPoint(IPAddress.Any, 80),
connection => connection.ReadAsync((ignore, buffer, bytesReceived) =>
{
if (bytesReceived <= 0) return;
connection.WriteAsync(buffer.Data, buffer.Offset, bytesReceived);
})))
{
Console.WriteLine("XF.Echo Server is ready to accept connections at {0}.", listener.EndPoint);
Console.WriteLine("Press any key to exit.");
Console.ReadKey(true);
}
}
}
}
For more information please refer to http://www.kodart.com
|