Project Overview
XmobiTea.ProtonNetServer is a lightweight, high-performance TCP, UDP, and WebSocket server library for .NET. It provides a flexible and scalable solution for building custom servers, handling thousands of simultaneous connections with ease. The library supports secure connections using SSL/TLS and is designed to be easily extensible, allowing developers to implement custom protocols and behaviors.
Installation
To install XmobiTea.ProtonNetServer, you can use NuGet:
dotnet add package XmobiTea.ProtonNetServer
Or via the NuGet Package Manager in Visual Studio:
- Right-click on your project in Solution Explorer and select "Manage NuGet Packages".
- Search for
XmobiTea.ProtonNetServer
.
- Click "Install".
Features
- TCP, UDP, and WebSocket Support: Provides robust implementations for TCP, UDP, and WebSocket protocols.
- SSL/TLS Support: Secure your connections with SSL/TLS using built-in support for secure protocols.
- High Performance: Optimized for handling thousands of simultaneous connections efficiently.
- Extensible Architecture: Easily extend and customize the server to support custom protocols and behaviors.
- Asynchronous Operations: Fully supports asynchronous I/O operations, ensuring scalability and responsiveness.
- Session Management: Built-in session management for maintaining state across connections.
- Network Statistics: Monitor network activity with detailed statistics for sent and received data.
Usage
Basic TCP Server
{
ReceiveBufferCapacity = 1024,
SendBufferCapacity = 1024,
KeepAlive = true
};
var server =
new TcpServer(
"127.0.0.1", 9000, options);
server.Start();
Console.WriteLine("Server started on 127.0.0.1:9000");
Console.ReadLine();
server.Stop();
Represents the configuration options for the TCP server.
Definition TcpServerOptions.cs:7
Represents a TCP server that can handle multiple client sessions.
Definition ITcpServer.cs:24
Definition TcpServerOptions.cs:2
Definition IHttpServer.cs:5
WebSocket Server with SSL
using XmobiTea.ProtonNetServer.Ssl;
var sslOptions = new SslOptions("server.pfx", "password");
{
NoDelay = true,
TcpKeepAliveTime = 60,
TcpKeepAliveInterval = 30,
TcpKeepAliveRetryCount = 5
};
var server =
new WssServer(
"127.0.0.1", 9001, options, sslOptions);
server.Start();
Console.WriteLine("Secure WebSocket server started on wss://127.0.0.1:9001");
Console.ReadLine();
server.Stop();
Represents a secure WebSocket server that inherits from HttpsServer and implements WebSocket function...
Definition IWsServer.cs:527
Supported Data Types
- TcpServerOptions: Configuration options for TCP servers.
- UdpServerOptions: Configuration options for UDP servers.
- WebSocket: A class representing a WebSocket connection, supporting text and binary frames.
- SslOptions: SSL/TLS options for secure connections.
Extensibility
XmobiTea.ProtonNetServer is designed with extensibility in mind. You can extend its functionality by:
- Custom Sessions: Inherit from
TcpSession
, UdpSession
, or WsSession
to create custom session handling logic.
- Custom Protocols: Implement custom protocol handling by overriding the
OnReceived
method in your session classes.
- Server Events: Override server lifecycle methods like
OnStarting
, OnStopping
, OnError
, etc., to add custom behavior.
Contributing
Contributions to XmobiTea.ProtonNetServer are welcome! Please follow these guidelines:
- Fork the repository.
- Create a new branch with a descriptive name.
- Commit your changes with clear and concise messages.
- Open a pull request to the
main
branch.
License
XmobiTea.ProtonNetServer is licensed under the MIT License. See the LICENSE
file for more details.
Acknowledgments
Special thanks to the open-source community for their contributions and continuous support.