开发者

Using a port number range on the TcpChannel class

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


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜