在 TcpChannel 类上使用端口号范围

发布于 2024-09-09 00:24:19 字数 209 浏览 1 评论 0原文

是否可以在 TcpChannel 类上指定一系列端口号,而不是固定端口或随机端口号。

目前,我们对远程通道使用固定端口号,但现在由于应用程序部署在 Citrix 环境中,我们需要使用一系列端口号来适应其安全环境。使用零作为端口号分配一个随机端口,然后该端口将被防火墙阻止,因此寻找可以指定要使用的端口号范围(例如 9000 - 9500)的东西

亲切的问候
诺埃尔

Is it possible to specify a range of port numbers on the TcpChannel class rather than a fixed port or random port number.

We currently use a fixed port number for a remoting channel, but now because the application is being deployed in a citrix environment we need to use a range of port numbers to fit within their security environment. Using zero as the port number allocates a random port which will then be blocked by their firewall, so looking for something that could possible specify a range of port numeers to use (e.g. 9000 - 9500)

Kind Regards
Noel

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

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

发布评论

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

评论(3

拿命拼未来 2024-09-16 00:24:19

下面是一个 vb.net 函数,它将返回一系列端口号中的下一个可用端口,以便您可以使用下一个可用端口打开套接字或执行任何需要的操作。

我并没有试图在同一个端口号上打开多个客户端或类似的疯狂事情。我只需要找出哪些端口号可供使用,并指导客户端使用该端口号。这是在 Citrix 环境中使用的,其中多个客户端尝试从不同的用户会话打开同一端口;使用下面的代码可以让我们解决这个问题。

''' <summary>
''' Routine to get the next available port number from a range of port numbers
''' </summary>
Private Function GetPortNumberFromRange(ByVal startPort As Integer, ByVal endPort As Integer) As Integer
    Dim ipProperties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
    Dim tcpInfos = ipProperties.GetActiveTcpConnections()
    Dim portRange = Linq.Enumerable.Range(startPort, endPort).ToList
    For Each tcpInfo In tcpInfos
        portRange.Remove(tcpInfo.LocalEndPoint.Port)
    Next
    If portRange.Count > 0 Then
        Return portRange(0)
    End If

End Function

Below is a vb.net function which will return back the next available port from a range of port number so that you can use the next available port to open up a socket or do whatever is required.

I was not trying to open up multiple clients on the same port number or anything mad like that. I just needed to figure out which port numbers where available for use and direct the client to use that port number. This was for use in a Citrix environment where multiple clients were attempting to open the same port from different user sessions; using the code below allow us to resolve the issue.

''' <summary>
''' Routine to get the next available port number from a range of port numbers
''' </summary>
Private Function GetPortNumberFromRange(ByVal startPort As Integer, ByVal endPort As Integer) As Integer
    Dim ipProperties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
    Dim tcpInfos = ipProperties.GetActiveTcpConnections()
    Dim portRange = Linq.Enumerable.Range(startPort, endPort).ToList
    For Each tcpInfo In tcpInfos
        portRange.Remove(tcpInfo.LocalEndPoint.Port)
    Next
    If portRange.Count > 0 Then
        Return portRange(0)
    End If

End Function
不…忘初心 2024-09-16 00:24:19

AFAIK,您不能在配置文件中指定这一点,但它当然可以在代码中完成。

AFAIK, you can't specify this in your config file, but it could certainly be done in code.

夏天碎花小短裙 2024-09-16 00:24:19

通道(包括 TcpChannel)旨在监听单个端口。如果您想监听多个端口,则需要多个通道来支持。

A Channel (TcpChannel included) is meant to listen to a single port. If you want to listen on multiple ports, you're going to need multiple Channels to support that.

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