GithubHelp home page GithubHelp logo

Comments (6)

DingpingZhang avatar DingpingZhang commented on August 21, 2024

你好,请确认一下你所安装的 HandyIpc 的版本,是否与下方相同?

    <PackageReference Include="HandyIpc" Version="0.5.2" />
    <PackageReference Include="HandyIpc.NamedPipe" Version="0.5.0" />
    <PackageReference Include="HandyIpc.Serializer.Json" Version="0.5.0" />

我对你提供的 Demo 进行了测试,在该版本下,不可复现此问题。

这是我的最小复现 Demo:

TestHandyIpc.zip

from handyipc.

heartacker avatar heartacker commented on August 21, 2024

你好,是不是 contract要在同一个命名空间内,如你的代码 TestHandyIpc.Contracts

我这边的情况是这个contract 代码是一样的,但是放在不同的文件和项目内部。
image

from handyipc.

DingpingZhang avatar DingpingZhang commented on August 21, 2024

你好,是不是 contract要在同一个命名空间内,如你的代码 TestHandyIpc.Contracts
我这边的情况是这个contract 代码是一样的,但是放在不同的文件和项目内部。

这不是推荐做法,因为共用相同的合同接口,才能做到统一管理,你在两边分别复制了一份接口,这在 C# 中实际上算两个不同的类型,当你修改了其中一个接口,导致其与另一个接口匹配不上时,将无法得到编译错误的提示,有潜在的维护隐患。

但具体到这个问题,其实有办法正常使用(不推荐)。出现这个问题的原因是:两个程序集中的 IDriver 本质上是不同的类型,所以框架会生成不同的标识符(key)来标识他们的代理实例,那么客户端的调用请求将匹配不上服务器的实例。

但是框架提供了自定义这个标识符的功能,你可以手动覆盖默认的标识符。只需要确保服务端和客户端的 "unique-key" 一致就可以正常调用,你可以看到,甚至服务端注册的接口 IDriver222 和客户端获取的接口 IDriver 连名字都不一样,但也能正常调用,只要方法的签名一致即可(相当于“鸭子类型”了):

// 在服务端注册这个接口时:
builder.Register<IDriver222, Driver>("unique-key");

// 在客户端获取这个接口时:
var driver = client.Resolve<IDriver>("unique-key");

from handyipc.

heartacker avatar heartacker commented on August 21, 2024

谢谢你的耐心解答。非常感谢 💯

from handyipc.

heartacker avatar heartacker commented on August 21, 2024

对了,顺便问一下,如果 server 没有运行的话, client 起来后调用会卡住不动,还不知道如何退出, 有没有办法检测server是否运行了?

from handyipc.

DingpingZhang avatar DingpingZhang commented on August 21, 2024

有没有办法检测server是否运行了?

框架目前没有支持,但可以使用 Mutex、 EventWaitHandle 等确保进程单例的方法来检查服务进程是否已启动,理论上服务器的进程是要确保单例的,否则,无法保证消息被发往哪个进程处理。

from handyipc.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.