Skip to content

Commit

Permalink
Merge pull request #28 from exomia/development
Browse files Browse the repository at this point in the history
v1.5.0.0
  • Loading branch information
baetz-daniel authored Aug 1, 2019
2 parents 8a5b08c + 29c3827 commit b825009
Show file tree
Hide file tree
Showing 37 changed files with 1,711 additions and 1,464 deletions.
7 changes: 7 additions & 0 deletions Example.Client/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
</configuration>
61 changes: 61 additions & 0 deletions Example.Client/Example.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{90A9560E-16E9-4008-B061-B5827AF69880}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Example.Client</RootNamespace>
<AssemblyName>Example.Client</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Exomia.Network\Exomia.Network.csproj">
<Project>{4a17dccb-d3de-48df-97a7-f46936096ca6}</Project>
<Name>Exomia.Network</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
75 changes: 75 additions & 0 deletions Example.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#region License

// Copyright (c) 2018-2019, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#endregion

#define TCP

using System;
using System.Text;
using System.Threading.Tasks;
using Exomia.Network;
using Exomia.Network.DefaultPackets;
using Exomia.Network.TCP;

namespace Example.Client
{
class Program
{
private static async Task Main(string[] args)
{
#if TCP
using (TcpClientEap client = new TcpClientEap())
#else
using (var client = new UdpClientEap())
#endif
{
client.Disconnected += (c, r) => { Console.WriteLine(r + " | Disconnected"); };
client.AddCommand(
(in Packet packet) =>
{
return Encoding.UTF8.GetString(packet.Buffer, packet.Offset, packet.Length);
}, 45);

client.AddDataReceivedCallback(
45, (client1, data) =>
{
Console.WriteLine(data + " -- OK");
return true;
});

Console.WriteLine(client.Connect("127.0.0.1", 3000) ? "CONNECTED" : "CONNECT FAILED");

byte[] request = Encoding.UTF8.GetBytes("get time");
for (int i = 0; i < 10; i++)
{
Response<PingPacket> res = await client.SendRPing();
if (res)
{
Console.WriteLine(
i +
"ping received " + TimeSpan.FromTicks((DateTime.Now.Ticks - res.Result.Timestamp) / 2)
.TotalMilliseconds);
}
else { Console.WriteLine("error receiving response"); }

Response<string> res2 = await client.SendR(
45, request, 0, request.Length, (in Packet packet) =>
{
return Encoding.UTF8.GetString(packet.Buffer, packet.Offset, packet.Length);
});

Console.WriteLine(res2 ? res2.Result : "error receiving response");
}

Console.WriteLine("press any key to exit...");
Console.ReadKey();
}
}
}
}
45 changes: 45 additions & 0 deletions Example.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#region License

// Copyright (c) 2018-2019, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#endregion

using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Example.Client")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Example.Client")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("90a9560e-16e9-4008-b061-b5827af69880")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
7 changes: 7 additions & 0 deletions Example.Server/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
</configuration>
61 changes: 61 additions & 0 deletions Example.Server/Example.Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7E2A2465-B98E-42B8-B8AB-DE890F2406BF}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Example.Server</RootNamespace>
<AssemblyName>Example.Server</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Exomia.Network\Exomia.Network.csproj">
<Project>{4a17dccb-d3de-48df-97a7-f46936096ca6}</Project>
<Name>Exomia.Network</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
79 changes: 79 additions & 0 deletions Example.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#region License

// Copyright (c) 2018-2019, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#endregion

#define TCP

using System;
using System.Text;
using Exomia.Network;
using Exomia.Network.TCP;

namespace Example.Server
{
class Program
{
private static void Main(string[] args)
{
using (Server server = new Server())
{
server.ClientConnected += (server1, client) =>
{
Console.WriteLine("Client connected: " + client.IPAddress);
};
server.ClientDisconnected += (server1, client, reason) =>
{
Console.WriteLine(reason + " Client disconnected: " + client.IPAddress);
};
server.AddCommand(
(in Packet packet) =>
{
return Encoding.UTF8.GetString(packet.Buffer, packet.Offset, packet.Length);
}, 45);
server.AddDataReceivedCallback(
45, (server1, client, data, responseid) =>
{
string request = (string)data;
Console.WriteLine($"Request: {request}");
byte[] buffer = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
server1.SendTo(client, 45, buffer, 0, buffer.Length, responseid);
return true;
});

Console.WriteLine(server.Run(3000));

Console.WriteLine("press any key to exit...");
Console.ReadKey();
}
}
}

#if TCP
class Server : TcpServerEapBase<ServerClient>
#else
class Server : UdpServerEapBase<ServerClient>
#endif
{
protected override bool CreateServerClient(out ServerClient serverClient)
{
serverClient = new ServerClient();
return true;
}

public Server(ushort expectedMaxClient = 32, ushort maxPacketSize = 65520)
: base(expectedMaxClient, maxPacketSize) { }
}

#if TCP
class ServerClient : TcpServerClientBase
#else
class ServerClient : UdpServerClientBase
#endif
{ }
}
45 changes: 45 additions & 0 deletions Example.Server/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#region License

// Copyright (c) 2018-2019, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

#endregion

using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Example.Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Example.Server")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7e2a2465-b98e-42b8-b8ab-de890f2406bf")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit b825009

Please sign in to comment.