diff options
Diffstat (limited to 'samples/CustomWireProtocol/ServerApp')
3 files changed, 144 insertions, 0 deletions
diff --git a/samples/CustomWireProtocol/ServerApp/Program.cs b/samples/CustomWireProtocol/ServerApp/Program.cs new file mode 100644 index 0000000..593dadf --- /dev/null +++ b/samples/CustomWireProtocol/ServerApp/Program.cs @@ -0,0 +1,41 @@ +using System; +using CommonLib; +using Hik.Communication.Scs.Communication.EndPoints.Tcp; +using Hik.Communication.Scs.Communication.Messages; +using Hik.Communication.Scs.Server; + +/* This application is build to demonstrate a CUSTOM WIRE PROTOCOL usage with SCS framework. + * This server application listens incoming messages from client applications using MyWireProtocol class. + */ + +namespace ServerApp +{ + public class Program + { + static void Main() + { + var server = ScsServerFactory.CreateServer(new ScsTcpEndPoint(10033)); + + server.WireProtocolFactory = new MyWireProtocolFactory(); //Set custom wire protocol factory! + server.ClientConnected += server_ClientConnected; + + server.Start(); + + Console.WriteLine("Press enter to stop server"); + Console.ReadLine(); + + server.Stop(); + } + + static void server_ClientConnected(object sender, ServerClientEventArgs e) + { + Console.WriteLine("A new client is connected. Address: " + e.Client.RemoteEndPoint); + e.Client.MessageReceived += Client_MessageReceived; + } + + static void Client_MessageReceived(object sender, MessageEventArgs e) + { + Console.WriteLine("A client sent a message: " + ((ScsTextMessage) e.Message).Text); + } + } +} diff --git a/samples/CustomWireProtocol/ServerApp/Properties/AssemblyInfo.cs b/samples/CustomWireProtocol/ServerApp/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..125c23c --- /dev/null +++ b/samples/CustomWireProtocol/ServerApp/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +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("ServerApp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ServerApp")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[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("bae7ad3a-ea6a-44f7-8429-89f23b17abfe")] + +// 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")] diff --git a/samples/CustomWireProtocol/ServerApp/ServerApp.csproj b/samples/CustomWireProtocol/ServerApp/ServerApp.csproj new file mode 100644 index 0000000..b624302 --- /dev/null +++ b/samples/CustomWireProtocol/ServerApp/ServerApp.csproj @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">x86</Platform> + <ProductVersion>8.0.30703</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F515CE95-6A3F-4E5E-867A-899FFFC90D43}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>ServerApp</RootNamespace> + <AssemblyName>ServerApp</AssemblyName> + <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> + <TargetFrameworkProfile>Client</TargetFrameworkProfile> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> + <PlatformTarget>x86</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> + <PlatformTarget>x86</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Scs, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\Scs-Binaries\Scs.dll</HintPath> + </Reference> + <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.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\CommonLib\CommonLib.csproj"> + <Project>{7F7D3248-4432-4E7B-9CFD-25982668AD5B}</Project> + <Name>CommonLib</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project>
\ No newline at end of file |