优化Redis 接收逻辑
This commit is contained in:
@@ -31,6 +31,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testwebservice", "testwebse
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvcApplication1", "MvcApplication1\MvcApplication1.csproj", "{733CA292-F36D-4DC7-8268-3337C5D1B540}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication4", "ConsoleApplication4\ConsoleApplication4.csproj", "{85BC55B1-083D-4AE9-8DE8-3DE59B654990}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -191,6 +193,16 @@ Global
|
||||
{733CA292-F36D-4DC7-8268-3337C5D1B540}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{733CA292-F36D-4DC7-8268-3337C5D1B540}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{733CA292-F36D-4DC7-8268-3337C5D1B540}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Debug|x86.Build.0 = Debug|x86
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Release|x86.ActiveCfg = Release|x86
|
||||
{85BC55B1-083D-4AE9-8DE8-3DE59B654990}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Binary file not shown.
@@ -324,7 +324,7 @@ namespace Common
|
||||
CSRedisClient client = WhitchRedisSlice(SliceNo);
|
||||
client.LPush(key, obj);
|
||||
}
|
||||
public static int MaxLen = 800000;
|
||||
public static long MaxLen = 1000000;
|
||||
public static void StreamAdd(int SliceNo, string key, string Value)
|
||||
{
|
||||
try
|
||||
@@ -333,9 +333,9 @@ namespace Common
|
||||
// 添加简单消息
|
||||
client.XAdd(key, MaxLen, "*", new ValueTuple<string, string>("__data", Value));
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
logger.Error("队列添加出异常了:"+ex.Message);
|
||||
}
|
||||
}
|
||||
public static void StreamConsume(int SliceNo, string key, string group = "UDPData", string consumer = "Crics1")
|
||||
|
||||
@@ -23,4 +23,48 @@ namespace CommonEntity
|
||||
//public string Gateway { get; set; }
|
||||
//public string DNS { get; set; }
|
||||
}
|
||||
public class RegisterInfo
|
||||
{
|
||||
public long hotel_id { get; set; }
|
||||
public string room_id { get; set; }
|
||||
public string device_id { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 1:下发,0:上报 默认0
|
||||
/// </summary>
|
||||
public ushort is_send { get; set; }
|
||||
public byte[] udp_raw { get; set; }
|
||||
public string extra { get; set; }
|
||||
|
||||
public int ip_type { get; set; }
|
||||
/// <summary>
|
||||
/// 机型编号
|
||||
/// </summary>
|
||||
public string model_num { get; set; }
|
||||
public string server_ip { get; set; }
|
||||
public string ip { get; set; }
|
||||
public string subnet_mask { get; set; }
|
||||
public string gateway { get; set; }
|
||||
public string dns { get; set; }
|
||||
public string version { get; set; }
|
||||
public string rcu_time { get; set; }
|
||||
public string launcher_version { get; set; }
|
||||
public string mac { get; set; }
|
||||
public string room_type_id { get; set; }
|
||||
public string config_version { get; set; }
|
||||
public string room_status { get; set; }
|
||||
public string season { get; set; }
|
||||
public string sys_lock_status { get; set; }
|
||||
public string authorization_time { get; set; }
|
||||
public string authorization_days { get; set; }
|
||||
public string room_num_remark { get; set; }
|
||||
public string room_type_remark { get; set; }
|
||||
public string room_remark { get; set; }
|
||||
|
||||
public string mcu_name { get; set; }
|
||||
public string central_control_name { get; set; }
|
||||
public string configure_hotel_name { get; set; }
|
||||
public string configure_room_type_name { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,6 +299,9 @@ namespace ConsoleApplication2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
byte[] ss111= Base64Url.Decode("qlUuAFQzU0E01oL4CIZhAQIABgAgAAAAAAAA/wICBwEAAAIbKgcCAAACGyp4Ig==");
|
||||
|
||||
57
ConsoleApplication4/ConsoleApplication4.csproj
Normal file
57
ConsoleApplication4/ConsoleApplication4.csproj
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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>{85BC55B1-083D-4AE9-8DE8-3DE59B654990}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ConsoleApplication4</RootNamespace>
|
||||
<AssemblyName>ConsoleApplication4</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="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>
|
||||
50
ConsoleApplication4/Program.cs
Normal file
50
ConsoleApplication4/Program.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
|
||||
namespace ConsoleApplication4
|
||||
{
|
||||
internal class UdpState
|
||||
{
|
||||
private UdpClient udpClient;
|
||||
public UdpState(UdpClient client)
|
||||
{
|
||||
this.udpClient = client;
|
||||
}
|
||||
public UdpClient UdpClient
|
||||
{
|
||||
get { return this.udpClient; }
|
||||
}
|
||||
}
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var udpClient = new UdpClient(3340);
|
||||
udpClient.Client.ReceiveBufferSize = 3 * 1024 * 1024;
|
||||
udpClient.BeginReceive(ReceiveCallback, new UdpState(udpClient));
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
public static void ReceiveCallback(IAsyncResult ar)
|
||||
{
|
||||
UdpState state = ar.AsyncState as UdpState;
|
||||
// 1. 结束异步接收,获取数据和远程端点
|
||||
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
|
||||
byte[] receivedData = state.UdpClient.EndReceive(ar, ref remoteEndPoint);
|
||||
|
||||
state.UdpClient.BeginReceive(ReceiveCallback, state);
|
||||
try
|
||||
{
|
||||
Console.WriteLine(11111111111111);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
ConsoleApplication4/Properties/AssemblyInfo.cs
Normal file
36
ConsoleApplication4/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("ConsoleApplication4")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ConsoleApplication4")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2026")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("3ac386f6-d433-4860-9b22-ee7e0dc298d4")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 内部版本号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
BIN
ConsoleApplication4/bin/Debug/ConsoleApplication4.exe
Normal file
BIN
ConsoleApplication4/bin/Debug/ConsoleApplication4.exe
Normal file
Binary file not shown.
BIN
ConsoleApplication4/bin/Debug/ConsoleApplication4.pdb
Normal file
BIN
ConsoleApplication4/bin/Debug/ConsoleApplication4.pdb
Normal file
Binary file not shown.
BIN
ConsoleApplication4/bin/Debug/ConsoleApplication4.vshost.exe
Normal file
BIN
ConsoleApplication4/bin/Debug/ConsoleApplication4.vshost.exe
Normal file
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||
<security>
|
||||
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
</assembly>
|
||||
@@ -0,0 +1,4 @@
|
||||
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\ConsoleApplication4.exe
|
||||
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\ConsoleApplication4.pdb
|
||||
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\obj\x86\Debug\ConsoleApplication4.exe
|
||||
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\obj\x86\Debug\ConsoleApplication4.pdb
|
||||
BIN
ConsoleApplication4/obj/x86/Debug/ConsoleApplication4.exe
Normal file
BIN
ConsoleApplication4/obj/x86/Debug/ConsoleApplication4.exe
Normal file
Binary file not shown.
BIN
ConsoleApplication4/obj/x86/Debug/ConsoleApplication4.pdb
Normal file
BIN
ConsoleApplication4/obj/x86/Debug/ConsoleApplication4.pdb
Normal file
Binary file not shown.
Binary file not shown.
@@ -261,6 +261,24 @@ namespace RCUHost.Implement
|
||||
hostRCU.RoomTypeRemark = roomtype_remark;
|
||||
hostRCU.UpdateTime = DateTime.Now;
|
||||
|
||||
RegisterInfo rsg = new RegisterInfo()
|
||||
{
|
||||
hotel_id=hotel_code,
|
||||
room_id=host.RoomNumber,
|
||||
device_id = HostNumberOnly,
|
||||
is_send=0,
|
||||
udp_raw=context.Data,
|
||||
ip_type=ipType,
|
||||
model_num = type_number,
|
||||
server_ip=server_ip,
|
||||
ip=lan_ip+":"+lan_port,
|
||||
subnet_mask=subnet_mask,
|
||||
gateway=gateway,
|
||||
dns=dns,
|
||||
version = software_version,
|
||||
|
||||
};
|
||||
|
||||
HostRepository.SetModelAndLauncher(host, hostRCU.ConfigVersion, software_version, lan_ip, lan_port, model, launcher_version, hostRCU.ExpireTime, hostRCU.SetExpireTime);
|
||||
|
||||
HostRCURepository.SaveOrUpdate(hostRCU);
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace RCUHost.Implement
|
||||
try
|
||||
{
|
||||
var redis = CSRedisCacheHelper.redis1;
|
||||
var data = redis.XReadGroup(group, consumer, 1000, 10, new ValueTuple<string, string>(UDPAllDataKey, ">"));
|
||||
var data = redis.XReadGroup(group, consumer, 500, 10, new ValueTuple<string, string>(UDPAllDataKey, ">"));
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
@@ -147,7 +147,7 @@ namespace RCUHost.Implement
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("消息队列失败:"+ex.Message);
|
||||
logger.Error("消息队列失败:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace RCUHost.Implement
|
||||
try
|
||||
{
|
||||
udpClient = new UdpClient(3339);
|
||||
udpClient.Client.ReceiveBufferSize = 5 * 1024 * 1024;
|
||||
udpClient.Client.ReceiveBufferSize = 3 * 1024 * 1024;
|
||||
uint IOC_IN = 0x80000000;
|
||||
uint IOC_VENDOR = 0x18000000;
|
||||
uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
|
||||
@@ -459,6 +459,8 @@ namespace RCUHost.Implement
|
||||
{
|
||||
IPEndPoint remoteEP111 = new IPEndPoint(IPAddress.Any, 0);
|
||||
byte[] receiveBuffer111 = state.UdpClient.EndReceive(ar, ref remoteEP111);
|
||||
state.UdpClient.BeginReceive(ReceiveCallback, state);
|
||||
|
||||
if (receiveBuffer111.Length > 0)
|
||||
{
|
||||
|
||||
@@ -719,17 +721,17 @@ namespace RCUHost.Implement
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.udpClient != null)
|
||||
{
|
||||
state.UdpClient.BeginReceive(ReceiveCallback, new UdpState(this.udpClient));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
//try
|
||||
//{
|
||||
// if (this.udpClient != null)
|
||||
// {
|
||||
// state.UdpClient.BeginReceive(ReceiveCallback, new UdpState(this.udpClient));
|
||||
// }
|
||||
//}
|
||||
//catch
|
||||
//{
|
||||
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1628,7 +1630,7 @@ namespace RCUHost.Implement
|
||||
#region 故意让UDP丢掉的数据包总数
|
||||
//insertcard 保留
|
||||
//if (cmdType != 0x0E||cmdType!=0x01)
|
||||
if (cmdType != 0E || cmdType != 0x03)
|
||||
if (cmdType != 0E && cmdType != 0x03)
|
||||
{
|
||||
if (DataTongJi.DefineLostPackage != 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user