Skip to content

Commit

Permalink
update in readme, version and examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
MUN1Z committed Aug 25, 2020
1 parent 6745861 commit 984cd84
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 66 deletions.
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ server.MessageReceivedHandler = OnMessageReceived;
server.Start();

// implements the callback for MessageReceivedHandler
private void OnMessageReceived(IClient client, KingBufferReader kingBuffer)
private void OnMessageReceived(IClient client, IKingBufferReader reader)
{
Console.WriteLine($"Received data from client {client.Id}, data length {kingBuffer.Length()}");
Console.WriteLine($"Received data from client {client.Id}, data length {reader.Length()}");
}

// send a message to all clients
using(var kingBuffer = KingBufferWriter.Create())
using(var writer = KingBufferWriter.Create())
{
kingBuffer.Write("Test message!");
server.SendMessageToAll(kingBuffer);
writer.Write("Test message!");
server.SendMessageToAll(writer);
}

// stop the server when you don't need it anymore
Expand All @@ -59,16 +59,16 @@ client.MessageReceivedHandler = OnMessageReceived;
client.Connect("127.0.0.1", 7171);

// implements the callback for MessageReceivedHandler
private void OnMessageReceived(KingBufferReader kingBuffer)
private void OnMessageReceived(IKingBufferReader reader)
{
Console.WriteLine($"Received data from server, data length {kingBuffer.Length()}");
Console.WriteLine($"Received data from server, data length {reader.Length()}");
}

/// send a message to server
using(var kingBuffer = KingBufferWriter.Create()
using(var writer = KingBufferWriter.Create()
{
kingBuffer.Write("Test message!");
client.SendMessage(kingBuffer);
writer.Write("Test message!");
client.SendMessage(writer);
}

// disconnect from the server when we are done
Expand All @@ -83,16 +83,16 @@ server.MessageReceivedHandler = OnMessageReceived;
server.Start(NetworkListenerType.UDP);

// implements the callback for MessageReceivedHandler
private void OnMessageReceived(IClient client, KingBufferReader kingBuffer)
private void OnMessageReceived(IClient client, IKingBufferReader reader)
{
Console.WriteLine($"Received data from client {client.Id}, data length {kingBuffer.Length()}");
Console.WriteLine($"Received data from client {client.Id}, data length {reader.Length()}");
}

// send a message to all clients
using(var kingBuffer = KingBufferWriter.Create())
using(var writer = KingBufferWriter.Create())
{
kingBuffer.Write("Test message!");
server.SendMessageToAll(kingBuffer);
writer.Write("Test message!");
server.SendMessageToAll(writer);
}

// stop the server when you don't need it anymore
Expand All @@ -107,16 +107,16 @@ client.MessageReceivedHandler = OnMessageReceived;
client.Connect("127.0.0.1", 7171, NetworkListenerType.UDP);

// implements the callback for MessageReceivedHandler
private void OnMessageReceived(KingBufferReader kingBuffer)
private void OnMessageReceived(IKingBufferReader reader)
{
Console.WriteLine($"Received data from server, data length {kingBuffer.Length()}");
Console.WriteLine($"Received data from server, data length {reader.Length()}");
}

/// send a message to server
using(var kingBuffer = KingBufferWriter.Create()
using(var writer = KingBufferWriter.Create()
{
kingBuffer.Write("Test message!");
client.SendMessage(kingBuffer);
writer.Write("Test message!");
client.SendMessage(writer);
}

// disconnect from the server when we are done
Expand All @@ -131,16 +131,16 @@ server.MessageReceivedHandler = OnMessageReceived;
server.Start(NetworkListenerType.WSText); // Or NetworkListenerType.WSBinary
// implements the callback for MessageReceivedHandler
private void OnMessageReceived(IClient client, KingBufferReader kingBuffer)
private void OnMessageReceived(IClient client, IKingBufferReader reader)
{
Console.WriteLine($"Received data from client {client.Id}, data length {kingBuffer.Length()}");
Console.WriteLine($"Received data from client {client.Id}, data length {reader.Length()}");
}

// send a message to all clients
using(var kingBuffer = KingBufferWriter.Create())
using(var writer = KingBufferWriter.Create())
{
kingBuffer.Write("Test message!");
server.SendMessageToAll(kingBuffer);
writer.Write("Test message!");
server.SendMessageToAll(writer);
}

// stop the server when you don't need it anymore
Expand All @@ -155,16 +155,16 @@ client.MessageReceivedHandler = OnMessageReceived;
client.Connect("127.0.0.1", 7171, NetworkListenerType.WSText); // Or NetworkListenerType.WSBinary
// implements the callback for MessageReceivedHandler
private void OnMessageReceived(KingBufferReader kingBuffer)
private void OnMessageReceived(IKingBufferReader reader)
{
Console.WriteLine($"Received data from server, data length {kingBuffer.Length()}");
Console.WriteLine($"Received data from server, data length {reader.Length()}");
}

/// send a message to server
using(var kingBuffer = KingBufferWriter.Create()
using(var writer = KingBufferWriter.Create()
{
kingBuffer.Write("Test message!");
client.SendMessage(kingBuffer);
writer.Write("Test message!");
client.SendMessage(writer);
}

// disconnect from the server when we are done
Expand Down
18 changes: 7 additions & 11 deletions examples/Benchmarks/KingNetwork.Benchmarks.Load/RunServer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using KingNetwork.Server;
using KingNetwork.Server.Interfaces;
using KingNetwork.Shared;
using KingNetwork.Shared.Interfaces;
using System;
using System.Diagnostics;
using System.Text;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class RunServer
/// </summary>
public static void StartServer()
{
_networkListenerType = NetworkListenerType.WS;
_networkListenerType = NetworkListenerType.WSText;
_server = new KingServer();
_server.OnMessageReceivedHandler = OnMessageReceived;

Expand Down Expand Up @@ -77,28 +78,23 @@ public static void StartServer()
/// </summary>
/// <param name="client">The client instance.</param>
/// <param name="kingBuffer">The king buffer from received message.</param>
private static void OnMessageReceived(IClient client, KingBufferReader kingBuffer)
private static void OnMessageReceived(IClient client, IKingBufferReader reader)
{
try
{
if (_networkListenerType == NetworkListenerType.WS)
if (_networkListenerType == NetworkListenerType.WSText)
{
Console.WriteLine($"OnMessageReceived: ");

var bytes = kingBuffer.ReadAllBytes();

string text = Encoding.UTF8.GetString(bytes);
Console.WriteLine(text);
Console.WriteLine($"OnMessageReceived: {reader.ReadString()}");
}
else
{
var buffer = KingBufferWriter.Create();
buffer.Write(kingBuffer.ReadString());
buffer.Write(reader.ReadString());

_server.SendMessage(client, buffer);

_messagesReceived++;
_dataReceived += kingBuffer.Length;
_dataReceived += reader.Length;
}
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using KingNetwork.Client;
using KingNetwork.Shared;
using KingNetwork.Shared.Interfaces;

namespace KingNetwork.HandlerExample.Client.PacketHandlers
{
Expand All @@ -9,11 +9,8 @@ namespace KingNetwork.HandlerExample.Client.PacketHandlers
/// </summary>
public class MyPacketHandlerOne : PacketHandler
{
/// <summary>
/// This method is responsible for receive the message from client packet handler.
/// </summary>
/// <param name="kingBuffer">The king buffer of received message.</param>
public override void HandleMessageData(KingBufferReader kingBuffer)
/// <inheritdoc/>
public override void HandleMessageData(IKingBufferReader reader)
{
Console.WriteLine("Received message in MyPacketHandlerOne");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using KingNetwork.Server;
using KingNetwork.Server.Interfaces;
using KingNetwork.Shared;
using KingNetwork.Shared.Interfaces;

namespace KingNetwork.HandlerExample.Server.PacketHandlers
{
Expand All @@ -10,12 +10,8 @@ namespace KingNetwork.HandlerExample.Server.PacketHandlers
/// </summary>
public class MyPacketHandlerOne : PacketHandler
{
/// <summary>
/// This method is responsible for receive the message from server packet handler.
/// </summary>
/// <param name="client">The connected client.</param>
/// <param name="kingBuffer">The king buffer received from message.</param>
public override void HandleMessageData(IClient client, KingBufferReader kingBuffer)
/// <inheritdoc/>
public override void HandleMessageData(IClient client, IKingBufferReader reader)
{
Console.WriteLine($"OnMessageReceived PacketOne from {client.Id}");
}
Expand Down
9 changes: 5 additions & 4 deletions examples/Unity/Chat/ChatMultiplayerDemoServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using KingNetwork.Server;
using KingNetwork.Server.Interfaces;
using KingNetwork.Shared;
using KingNetwork.Shared.Interfaces;
using System;

namespace ChatMultiplayerDemoServer
Expand Down Expand Up @@ -56,15 +57,15 @@ static void Main(string[] args)
/// Method responsible for execute the callback of on message received handler.
/// </summary>
/// <param name="client">The client instance.</param>
/// <param name="kingBuffer">The king buffer from received message.</param>
private void OnMessageReceived(IClient client, KingBufferReader kingBuffer)
/// <param name="reader">The king buffer reader from received message.</param>
private void OnMessageReceived(IClient client, IKingBufferReader reader)
{
try
{
switch (kingBuffer.ReadMessagePacket<MyPackets>())
switch (reader.ReadMessagePacket<MyPackets>())
{
case MyPackets.Message:
Console.WriteLine($"Received message: {kingBuffer.ReadString()}.");
Console.WriteLine($"Received message: {reader.ReadString()}.");
_server.SendMessageToAllMinus(client, KingBufferWriter.Create());
break;
}
Expand Down
13 changes: 7 additions & 6 deletions examples/Unity/CubesSimple/CubesMultiplayerDemoServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using KingNetwork.Server;
using KingNetwork.Server.Interfaces;
using KingNetwork.Shared;
using KingNetwork.Shared.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -123,18 +124,18 @@ static void Main(string[] args)
/// Method responsible for execute the callback of on message received handler.
/// </summary>
/// <param name="client">The client instance.</param>
/// <param name="kingBuffer">The king buffer from received message.</param>
private void OnMessageReceived(IClient client, KingBufferReader kingBuffer)
/// <param name="reader">The king buffer reader from received message.</param>
private void OnMessageReceived(IClient client, IKingBufferReader reader)
{
try
{
switch (kingBuffer.ReadMessagePacket<MyPackets>())
switch (reader.ReadMessagePacket<MyPackets>())
{
case MyPackets.PlayerPosition:

float x = kingBuffer.ReadInt64();
float y = kingBuffer.ReadInt64();
float z = kingBuffer.ReadInt64();
float x = reader.ReadInt64();
float y = reader.ReadInt64();
float z = reader.ReadInt64();

Console.WriteLine($"Got position packet : {x} | {y} | {z}");

Expand Down
3 changes: 2 additions & 1 deletion src/KingNetwork.Client/KingNetwork.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.2</Version>
<LangVersion>7.3</LangVersion>
<Version>1.0.3</Version>
<PackageProjectUrl>https://github.com/Mun1z/KingNetwork/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Mun1z/KingNetwork/</RepositoryUrl>
<RepositoryType>github</RepositoryType>
Expand Down
2 changes: 1 addition & 1 deletion src/KingNetwork.Server/KingNetwork.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<PackageTags>socket, tcp, udp, king, network, kingnetwork, mun1z</PackageTags>
<RepositoryType>github</RepositoryType>
<RepositoryUrl>https://github.com/Mun1z/KingNetwork/</RepositoryUrl>
Expand Down
1 change: 1 addition & 0 deletions src/KingNetwork.Shared/KingNetwork.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<Version>1.0.3</Version>
<Description>KingNetwork is an open source library to facilitate the creation and communication of clients and servers through TCP, UDP and Web sockets.</Description>
<Copyright>Felipe Muniz (Mun1z)</Copyright>
Expand Down

0 comments on commit 984cd84

Please sign in to comment.