Prechádzať zdrojové kódy

zmq测试异步request reply

tanghai 12 rokov pred
rodič
commit
fa0fecca91

+ 15 - 3
CSharp/CSharp.sln

@@ -68,6 +68,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ENetExe", "Platform\ENetExe
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2814EB55-E1C2-4751-AC14-94116DA9D22B}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZmqTest", "Platform\ZmqTest\ZmqTest.csproj", "{AAEAFEF6-C3CC-4507-A012-04732EAA088A}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -360,6 +362,18 @@ Global
 		{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Release|Mixed Platforms.Build.0 = Release|Any CPU
 		{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Release|Win32.ActiveCfg = Release|Any CPU
 		{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Release|x86.ActiveCfg = Release|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Debug|Win32.ActiveCfg = Debug|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Release|Any CPU.Build.0 = Release|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Release|Win32.ActiveCfg = Release|Any CPU
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A}.Release|x86.ActiveCfg = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -378,6 +392,7 @@ Global
 		{D0B4CFAC-A368-4742-9863-68776CFA9938} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{901A8E5C-C4C6-4C3C-8E18-068D75119F5D} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{CBA52DC8-1C80-4A79-9AC5-73514EBBD749} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
+		{AAEAFEF6-C3CC-4507-A012-04732EAA088A} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{5D6ECBCD-BE14-4DCB-BAEC-57089748B164} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
 		{5AA48F9A-455D-4CD8-A605-A3AC38283E60} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
 		{B07D70E7-F902-4F67-A486-B7AF27D6B813} = {C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}
@@ -390,7 +405,4 @@ Global
 		{CB5BCF0A-4741-477A-94C6-49ECA782555F} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
 		{0FA529D1-D0A9-4A8E-90F5-117CE80F2EDE} = {D0CC1FF4-2747-4278-A51F-BE9AA959175B}
 	EndGlobalSection
-	GlobalSection(Performance) = preSolution
-		HasPerformanceSessions = true
-	EndGlobalSection
 EndGlobal

+ 36 - 0
CSharp/Platform/ZmqTest/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过以下特性集 
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("ZmqTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("ZmqTest")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型 
+// 对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
+// 请将该类型上的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("3bf57ebf-3d07-4c39-8148-70674cf3b9e5")]
+
+// 程序集的版本信息由以下四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”: 
+// [assembly:  AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 64 - 0
CSharp/Platform/ZmqTest/ZmqReqRepTest.cs

@@ -0,0 +1,64 @@
+using System.Threading.Tasks;
+using Log;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using NetMQ;
+
+namespace ZmqTest
+{
+	[TestClass]
+	public class ZmqReqRepTest
+	{
+		const string address = "tcp://127.0.0.1:5001";
+
+		[TestMethod]
+		public void TestMethod()
+		{
+			var task1 = Task.Factory.StartNew(Server);
+			var task2 = Task.Factory.StartNew(Client);
+			Task.WaitAll(task1, task2);
+		}
+
+		private static void Client()
+		{
+			using (var context = NetMQContext.Create())
+			{
+				using (var req = context.CreateRequestSocket())
+				{
+					var poller = new Poller();
+					req.Connect(address);
+					req.ReceiveReady += (sender, args) =>
+					{
+						bool hasMore;
+						string msg = args.Socket.ReceiveString(true, out hasMore);
+						Logger.Debug(string.Format("req: {0}", msg));
+						poller.Stop();
+					};
+					poller.AddSocket(req);
+					poller.Start();
+				}
+			}
+		}
+
+		private static void Server()
+		{
+			using (var context = NetMQContext.Create())
+			{
+				using (var rep = context.CreateResponseSocket())
+				{
+					var poller = new Poller();
+					poller.AddSocket(rep);
+					rep.Bind(address);
+					rep.ReceiveReady += (sender, args) =>
+					{
+						bool hasMore;
+						string msg = args.Socket.ReceiveString(true, out hasMore);
+						Logger.Debug(string.Format("rep: {0}", msg));
+						args.Socket.Send(msg, true);
+						poller.Stop();
+					};
+					poller.Start();
+				}
+			}
+		}
+	}
+}

+ 98 - 0
CSharp/Platform/ZmqTest/ZmqTest.csproj

@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{AAEAFEF6-C3CC-4507-A012-04732EAA088A}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>ZmqTest</RootNamespace>
+    <AssemblyName>ZmqTest</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
+    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
+    <IsCodedUITest>False</IsCodedUITest>
+    <TestProjectType>UnitTest</TestProjectType>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <RestorePackages>true</RestorePackages>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <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|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\Bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="NetMQ">
+      <HintPath>..\..\packages\NetMQ.3.3.0.8\lib\net40\NetMQ.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+  </ItemGroup>
+  <Choose>
+    <When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
+      <ItemGroup>
+        <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+      </ItemGroup>
+    </When>
+    <Otherwise>
+      <ItemGroup>
+        <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
+      </ItemGroup>
+    </Otherwise>
+  </Choose>
+  <ItemGroup>
+    <Compile Include="ZmqReqRepTest.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Log\Log.csproj">
+      <Project>{72e16572-fc1f-4a9e-bc96-035417239298}</Project>
+      <Name>Log</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Choose>
+    <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
+      <ItemGroup>
+        <Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+          <Private>False</Private>
+        </Reference>
+        <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+          <Private>False</Private>
+        </Reference>
+        <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+          <Private>False</Private>
+        </Reference>
+        <Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+          <Private>False</Private>
+        </Reference>
+      </ItemGroup>
+    </When>
+  </Choose>
+  <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.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>

+ 4 - 0
CSharp/Platform/ZmqTest/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="NetMQ" version="3.3.0.8" targetFramework="net45" />
+</packages>