summaryrefslogtreecommitdiffstats
path: root/samples/SimpleMessaging/ServerApp
diff options
context:
space:
mode:
Diffstat (limited to 'samples/SimpleMessaging/ServerApp')
-rw-r--r--samples/SimpleMessaging/ServerApp/Program.cs66
-rw-r--r--samples/SimpleMessaging/ServerApp/Properties/AssemblyInfo.cs36
-rw-r--r--samples/SimpleMessaging/ServerApp/ServerApp.csproj61
3 files changed, 163 insertions, 0 deletions
diff --git a/samples/SimpleMessaging/ServerApp/Program.cs b/samples/SimpleMessaging/ServerApp/Program.cs
new file mode 100644
index 0000000..449cf0c
--- /dev/null
+++ b/samples/SimpleMessaging/ServerApp/Program.cs
@@ -0,0 +1,66 @@
+using System;
+using Hik.Communication.Scs.Communication.EndPoints.Tcp;
+using Hik.Communication.Scs.Communication.Messages;
+using Hik.Communication.Scs.Server;
+
+/* This program is build to demonstrate a server application that listens incoming
+ * client connections and reply messages.
+ */
+
+namespace ServerApp
+{
+ class Program
+ {
+ static void Main()
+ {
+ //Create a server that listens 10085 TCP port for incoming connections
+ var server = ScsServerFactory.CreateServer(new ScsTcpEndPoint(10085));
+
+ //Register events of the server to be informed about clients
+ server.ClientConnected += Server_ClientConnected;
+ server.ClientDisconnected += Server_ClientDisconnected;
+
+ server.Start(); //Start the server
+
+ Console.WriteLine("Server is started successfully. Press enter to stop...");
+ Console.ReadLine(); //Wait user to press enter
+
+ server.Stop(); //Stop the server
+ }
+
+ static void Server_ClientConnected(object sender, ServerClientEventArgs e)
+ {
+ Console.WriteLine("A new client is connected. Client Id = " + e.Client.ClientId);
+
+ //Register to MessageReceived event to receive messages from new client
+ e.Client.MessageReceived += Client_MessageReceived;
+ }
+
+ static void Server_ClientDisconnected(object sender, ServerClientEventArgs e)
+ {
+ Console.WriteLine("A client is disconnected! Client Id = " + e.Client.ClientId);
+ }
+
+ static void Client_MessageReceived(object sender, MessageEventArgs e)
+ {
+ var message = e.Message as ScsTextMessage; //Server only accepts text messages
+ if (message == null)
+ {
+ return;
+ }
+
+ //Get a reference to the client
+ var client = (IScsServerClient)sender;
+
+ Console.WriteLine("Client sent a message: " + message.Text +
+ " (Cliend Id = " + client.ClientId + ")");
+
+ //Send reply message to the client
+ client.SendMessage(
+ new ScsTextMessage(
+ "Hello client. I got your message (" + message.Text + ")",
+ message.MessageId //Set first message's id as replied message id
+ ));
+ }
+ }
+}
diff --git a/samples/SimpleMessaging/ServerApp/Properties/AssemblyInfo.cs b/samples/SimpleMessaging/ServerApp/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..c0a3988
--- /dev/null
+++ b/samples/SimpleMessaging/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("849b296f-ea34-47ab-a0e1-d8a178496264")]
+
+// 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/SimpleMessaging/ServerApp/ServerApp.csproj b/samples/SimpleMessaging/ServerApp/ServerApp.csproj
new file mode 100644
index 0000000..2c79b88
--- /dev/null
+++ b/samples/SimpleMessaging/ServerApp/ServerApp.csproj
@@ -0,0 +1,61 @@
+<?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>{3731733F-5B49-4677-B353-43475305644D}</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>
+ <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