远程处理 - 有关客户端的信息。 C#

发布于 2024-07-23 01:12:48 字数 230 浏览 10 评论 0原文

在 .net 2.0 上使用远程处理时是否可以找到/获取有关连接客户端的一些信息? 我想知道有关服务器端连接客户端的一些信息,以便我可以采取相应的行动? 这是一个小型且非常本地化的应用程序,同时连接/请求的客户端数量最多不会超过 10 个。

在每个函数中传递客户端引用? (或一些标识符)? 我可以这样做,但我更愿意只从请求/连接客户端获取信息。 IP 地址或类似的地址就更好了。

问候

Is it possible to find out / get some information about the connecting client when using remoting on .net 2.0? I like to know get some information about the connecting client on the server side, so I can act accordingly? This is a small and very local application that Never will have more then max 10 simultaneously connecting/requesting clients.

pass client reference in each function? (or some identifier)? I could do it this way, but I would prefer to just get the information from the request/connecting client. Ip-address or similar would be nice.

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七堇年 2024-07-30 01:12:48

这个问题可能有您正在寻找的答案。

我删除了可能对您来说不重要的部分,并留下了实际获取 IP 地址的部分。

public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, 
    IMessage requestmessage, ITransportHeaders requestHeaders, 
    System.IO.Stream requestStream, out IMessage responseMessage, 
    out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)
{
    // Get the IP address and add it to the call context.
    IPAddress ipAddr = (IPAddress)requestHeaders[CommonTransportKeys.IPAddress];
}

This question might have the answer you're looking for.

I stripped out the parts that probably don't matter to you and left the part that actually grabs the IPAddress.

public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, 
    IMessage requestmessage, ITransportHeaders requestHeaders, 
    System.IO.Stream requestStream, out IMessage responseMessage, 
    out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)
{
    // Get the IP address and add it to the call context.
    IPAddress ipAddr = (IPAddress)requestHeaders[CommonTransportKeys.IPAddress];
}
2024-07-30 01:12:48

这个问题显示了 URI 的明显格式,即 URI ObjRef 您从 RemotingServices.GetObjRefForProxy 时你向它传递一个远程对象。 前两个斜杠之间的字符串是每个进程的 GUID,它从本地程序的角度唯一标识客户端。

就我而言,我只需要某种方法来识别客户端,而不是它的 IP 地址(无论如何,这对于非 TCP 通道是无效的),所以这对我有用。

This question shows the apparent format of a URI, i.e. the URI property of the ObjRef you get from RemotingServices.GetObjRefForProxy when you pass it a remote object. The string between the first two slashes is a per-process GUID, which uniquely identifies the client from the perspective of the local program.

In my case, I just needed some way to identify the client, not its IP address (which wouldn't be valid with a non-TCP channel anyway), so this worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文