handyorg / handyipc Goto Github PK
View Code? Open in Web Editor NEWAn out-of-the-box inter-process communication (IPC) library, which can also be seen as a remote Ioc container.
License: MIT License
An out-of-the-box inter-process communication (IPC) library, which can also be seen as a remote Ioc container.
License: MIT License
0.0 感觉好麻烦的样子,一个简单的库要安装3个包
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Threading.ThreadPoolWorkQueue.TryDequeueTimeSensitiveWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dequeue(System.Threading.ThreadPoolWorkQueueThreadLocals, Boolean ByRef)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
由语法分析得到的 AttributeSyntax.Name 只能获得用户输入的原样字符串,故一个 Attribute 可能有以下的多种形式:
甚至可能无法去除末尾的空格、换行符、tab 等不影响语法的无意义字符:
迁移到语义化模型进行分析可以解决此问题。
本需求将在实现 #12 后再考虑,其实现经验将有利于本需求。
Newtonsoft.Json.JsonSerializationException
HResult=0x80131500
Message=Error converting value "System.NotSupportedException, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" to type 'System.Type'. Path '', line 1, position 121.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at HandyIpc.Serializer.Json.Extensions.ToObject(Byte[] bytes, Type type)
at HandyIpc.Serializer.Json.JsonSerializer.Deserialize(Byte[] bytes, Type type)
at HandyIpc.Core.Response.TryParse(Byte[] bytes, Type valueType, ISerializer serializer, Object& value, Exception& exception)
at HandyIpc.Core.GeneratorHelper.UnpackResponse[T](Byte[] bytes, ISerializer serializer)
at IpcServer.ClientProxyIDriver.global::IpcServer.IDriver.AddFloat(Single x_, Single y_) in D:\heart\Git\IpcDemo\IpcClientDll\HandyIpc.Generator\HandyIpc.Generator.SourceGenerator\IDriver.ClientProxy.g.cs:line 33
at IpcClientDll.IpcDriver.AddFloat(Single x, Single y) in D:\heart\Git\IpcDemo\IpcClientDll\IpcDriver.cs:line 91
at IpcClient.Program.Main(String[] args) in D:\heart\Git\IpcDemo\IpcClient\Program.cs:line 23
此异常最初是在此调用堆栈中引发的:
[外部代码]
内部异常 1:
ArgumentException: Could not cast or convert from System.String to System.Type.
[IpcContract]
public interface IDriver
{
float AddFloat(float x, float y);
void WriteMemery(uint addr, byte[] data);
byte[] ReadMemery(uint addr, uint lens);
}
我测试在服务端没有开启的情况下,客户端的方法会一直等待直至服务端开启?
那么我如何在调用方法前,确认服务端已开启呢?
设计行为:当检测到 [IpcContract]
接口派生自 IDisposable
时,会在客户端侧生成的代码(ClientProxy)里自动实现 Dispose()
方法,其行为是:调用该方法时,释放 IpcClientHub
内部的 ClientProxy
实例缓存。
由于目前没有采用语义化模型解析,无法区分值类型和引用类型,只将得到的 token 直接拼接,故导致该问题。
采用语义化模型后,该问题将得到解决。
当前的合同接口仅支持方法成员,按目前设定:Server 在同一个域内应该是唯一的,不允许启动第二个 Server 实例,以避免 Client 无法区分服务的提供者;而 Client 方则允许创建多个实例与唯一的 Server 交互,但交互方式仅为:Client 调用 Server,Server 在本次调用中应答一次 Client,是单对单的交互方式,还缺乏一种单对多的通知方式,即多播事件。
使当前的合同接口可以定义事件,事件的行为应当是:Server 发布事件后,所有 Client 实例(可能有多个)中订阅了该事件的 Handler 都应该被触发。Client 之间若想交互,仅可以通过调用 Server 方法以触发某个 Server Event 的方式进行。
该 Feature 本质上是:
考虑到以下问题,我们并不能简单地将目前的 SenderBase
和 ReceiverBase
进行互换:Tcp 中,同一台机器中的同一个端口仅允许被一个实例监听,如果 Client 侧也创建 ReceiverBase
,那么端口号将不方便选取,选取后也还需要通知 Server 侧,实现起来比较麻烦;NamedPipe 虽然允许创建多个同名 Pipe,但多个进程中包含的同名 ServerStream 也会导致 Client 无法区分正确的连接目标。
所以,应当借助 Tcp 和 NamedPipe 的全双工能力实现反向的通知。具体的:
服务端代码
static void Main(string[] args)
{
// 创建一个容器服务器 Builder。
ContainerServerBuilder serverBuilder = new ContainerServerBuilder();
serverBuilder.UseNamedPipe("JgkljServe").UseJsonSerializer();
serverBuilder.Register<IHansLaserServe, HansLaserServe>();
using (var server = serverBuilder.Build())
{
server.Start();
//检查状态进行阻塞,降低CPU使用率
while (server.IsRunning)
Task.Delay(1000).Wait();
}
}
发生异常: CLR/System.ArgumentException
“System.ArgumentException”类型的未经处理的异常在 HandyIpc.dll 中发生 : 'The bytes is not valid response data.'
在 HandyIpc.Core.Response.TryParse(Byte[] bytes, Type valueType, ISerializer serializer, Object& value, Exception& exception)
在 HandyIpc.Core.GeneratorHelper.UnpackResponse[T](Byte[] bytes, ISerializer serializer)
在Driver.ClientProxyIDriver.global::Driver.IDriver.WriteMemory(UInt32 addr_, UInt32 value_, Nullable`1 channel_)
uint ReadMemory(uint addr, int? channel = null); // 这个正常,
void WriteMemory(uint addr, uint value, int? channel = null); 这个报错
I'm getting:
System.InvalidOperationException: 'IDemo doesn't look like a Ipc interface.'
When running:
[IpcContract]
public interface IDemo
{
double Add(double x, double y);
}
public class Demo : IDemo
{
public double Add(double x, double y)
{
return x + y;
}
}
ContainerServerBuilder serverBuilder = new ContainerServerBuilder();
serverBuilder.UseNamedPipe("ec57043f-465c-4766-ae49-b9b1ee9ac571");
serverBuilder.Register<IDemo, Demo>();
using (var server = serverBuilder.Build())
{
server.Start();
}
What am I doing wrong?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.