Darki.SimpleNET 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Darki.SimpleNET --version 1.0.0
                    
NuGet\Install-Package Darki.SimpleNET -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Darki.SimpleNET" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Darki.SimpleNET" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Darki.SimpleNET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Darki.SimpleNET --version 1.0.0
                    
#r "nuget: Darki.SimpleNET, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Darki.SimpleNET@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Darki.SimpleNET&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Darki.SimpleNET&version=1.0.0
                    
Install as a Cake Tool

TCP

Creating a Server To create a use the Server Class in the TCP Folder (SimpleNET.TCP)

NOTE! The whole Server has Debug Messages using Console

Server server = new Server(ip, port);

The Constructor has 2 Parameters:

  1. IP of the Server (string)
  2. Port of the Server (int32)

Server server = new Server("127.0.0.1", 1025);

WARNING! You shouldn't use Ports below 1025 to prevent conflicts!

So now we created our Server object. To start the Server we can use the Start Method (Server#Start())

server.Start();

This starts the Server. Now Clients can connect to the Server.

To stop the Server you can use the Stop Method (Server#Stop())

server.Stop();

This stops the Server and all Clients gets kicked.

Create a Client To connect to the Server you have to use the Client Class in the TCP Folder (SimpleNET.TCP)

Client client = new Client(ip, port, name, id);

The Constructor has 4 Parameters:

  1. IP of the Machine with the running Server (string)
  2. Port of the running Server (int32)
  3. Name of the Client (string)

    NOTE! Can be empty when you don't want a Username

  4. ID of the Client (Guid)

Client client = new Client("127.0.0.1", 1025, Darki, Guid.NewGuid());

The Client will automatically try to connect to the Server.

If you want to close the Connection you can use the Close Method (Client#Close())

client.Close();

Sending Data To send Data over the Network SimpleNET uses a Packet System. In the Data Folder is a Class called Packet. Its abstract. So to send for Example a Message you have to create a Class extending Packet

IMPORTANT! To Convert the Object SimpleNET uses Binary Serialization so you have to mark your class as Serializable

[Serializable]
public class PacketSendMessage : Packet
{
	public string Message { get; set; }
}

You can design the Class like you want to. The Packet Class doesn't add a default Constructor or Method that have to be overridden. The only thing the Packet Class delivers is a ToBytes Method and a ToPacket Method.


To send the Packet to the Server the Client Class delivers a SendPacket Method

client.SendPacket(new PacketSendMessage("Ping!"));

Done. The Packet now gets send to the Server.


To send the Packet back to the Client you have to use the SendPacket Method in the ServerHandledClient Class. To get the Class you can use Lambda to filter the Clients List in the Server Class

ServerHandledClient client = server.Clients.Find(x => x.ID == id);

And then use the SendPacket Method

client.SendPacket(new PacketSendMessage("Pong!"));

To broadcast a Packet you can iterate through the Clients List in the Server Class

foreach(ServerHandledClient client in server.Clients)
{
    client.SendPacket(new PacketSendMessage("Pong!"));
}

Events The SimpleNET Library delivers some default Events.

Server Events:

  • ConnectionLost (Param: ServerHandledClient): Gets called when a Client losts Connection
  • ConnectionOpened (Param: ServerHandledClient): Gets called when a Client connected to the Server
  • PacketReceived (Param: ServerHandledClient, Packet): Gets called when a Packet got received from a Client

Client Events:

  • ConnectionLost (Param: none): Gets called the Client losts the Connection
  • ConnectionFailled (Param: none): Gets called when the Connection to the Server failed
  • PacketReceived (Param: Packet): Gets called when a Packet got received from the Server

End of Text I hope you like the SimpleNET. I'll will expand the Library over time. Thank you for using my Library. For sugestions, questions or just for thanks me you can email me under rageskilln@gmail.com. See ya^^

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated

Adding TCP Server Client Functions