以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]HttpServer如何获取服务端口 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=176734) |
-- 作者:YOU -- 发布时间:2022/4/25 10:03:00 -- [求助]HttpServer如何获取服务端口 启动HttpServer服务如何判断该端口是否已启动,避免报错? 2022-04-25 09:44:45.2756 在前缀“http://*:8809/”上侦听失败,因为它与计算机上的现有注册冲突。 在 System.Net.HttpListener.AddPrefix(String uriPrefix) 在 System.Net.HttpListenerPrefixCollection.Add(String uriPrefix) 在 UserCode.AIoKhem6dKAJF6BtN(ControlEventArgs e)
|
-- 作者:有点蓝 -- 发布时间:2022/4/25 10:06:00 -- http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=175194 |
-- 作者:YOU -- 发布时间:2022/4/25 11:13:00 -- 如何批量判断指定的几个端口? |
-- 作者:有点蓝 -- 发布时间:2022/4/25 11:37:00 -- 使用循环:http://www.foxtable.com/webhelp/topics/0226.htm |
-- 作者:YOU -- 发布时间:2022/4/25 11:51:00 -- 这个代码怎么优化一下 Dim t As String = "TCP" \'协议 Dim port0 As Boolean = False Dim port1 As Boolean = False Dim port2 As Boolean = False Dim port3 As Boolean = False Dim properties As System.Net.NetworkInformation.IPGlobalProperties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties() Dim ipendpoints() As System.Net.IPEndPoint If t = "TCP" Then ipendpoints = properties.GetActiveTcpListeners() Else ipendpoints = properties.GetActiveUdpListeners() End If For Each ipendpoint As System.Net.IPEndPoint In ipendpoints If ipendpoint.Port = 8880 Then port0 = True Output.Show( "8880端口使用中") ElseIf ipendpoint.Port = 8881 Then port1 = True Output.Show( "8881端口使用中") ElseIf ipendpoint.Port = 8882 Then port2 = True Output.Show( "8882端口使用中") ElseIf ipendpoint.Port = 8883 Then port3 = True Output.Show( "8883端口使用中") End If Next ipendpoints = Nothing properties = Nothing If port0 = False Then Output.Show( "8880端口启动成功") HttpServer.Prefixes.Add("http://*:8880/") HttpServer.Start() PopMessage("8880端口启动成功,感谢您的使用!","温馨提示",,5) ElseIf port1 = False Then Output.Show( "8881端口启动成功") HttpServer.Prefixes.Add("http://*:8881/") HttpServer.Start() PopMessage("8881端口启动成功,感谢您的使用!","温馨提示",,5) ElseIf port2 = False Then Output.Show( "8882端口启动成功") HttpServer.Prefixes.Add("http://*:8882/") HttpServer.Start() PopMessage("8882端口启动成功,感谢您的使用!","温馨提示",,5) ElseIf port3 = False Then Output.Show( "8883端口启动成功") HttpServer.Prefixes.Add("http://*:8883/") HttpServer.Start() PopMessage("8883端口启动成功,感谢您的使用!","温馨提示",,5) End If
|
-- 作者:有点蓝 -- 发布时间:2022/4/25 12:14:00 -- Dim t As String = "TCP" \'协议 dim lst as new list(of integer) lst.addrangd({8880,8881,8882,8883}) Dim properties As System.Net.NetworkInformation.IPGlobalProperties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties() Dim ipendpoints() As System.Net.IPEndPoint If t = "TCP" Then ipendpoints = properties.GetActiveTcpListeners() Else ipendpoints = properties.GetActiveUdpListeners() End If For Each ipendpoint As System.Net.IPEndPoint In ipendpoints lst.remove(ipendpoint.Port) Output.Show(ipendpoint.Port & "端口使用中") Next if lst.count> 0 then HttpServer.Prefixes.Add("http://*:" & lst(0) & "/") HttpServer.Start() end if
|
-- 作者:YOU -- 发布时间:2022/4/25 12:34:00 -- lst.addrangd({8880,8881,8882,8883}) |
-- 作者:有点蓝 -- 发布时间:2022/4/25 13:35:00 -- http://www.foxtable.com/webhelp/topics/0217.htm |