关于NetBox2.8端口问题

NetBox端口自动分配
本文介绍了一款基于ASP的单机练习系统使用NetBox 2.8进行端口自动分配的方法。考虑到NetBox已停止更新,作者自行研究并实现了端口冲突检查及自动分配功能,确保了程序在不同环境下稳定运行。
这几天公司在搞单机练习版(asp程序),为了封装程序,使用的是netbox2.8.在端口问题上给技术支持带的压力挺大.
我们自己定一个端口,到了用户那里,可能该端口已被占用.
由于Netbox已经停止开发了,没有任何的技术支持.所以只有自己去研究了.发现netbox的语言,和VB极为类似,可以说就是VB的语法,
加入了Netbox自己的对象而已.昨天解决了以后今天又优化了一下,我想应该是没有任何问题了.



Dim httpd

dim Path 

Dim ServerPort

Dim b_createport



path =NetBox.ApplicationPath

NetBox.ConfigFile = path & "main.ini"

ServerPort = netBox.Config("Server","Port")



Set httpd = NetBox.CreateObject("NetBox.HttpServer")

IF ServerPort="" THen

    ServerPort = 80

    netBox.Config("Server","Port") = ServerPort

End If



Shell.Service.Icon = path & netBox.Config("config","ICON")

Shell.Service.RunService "NBWeb", "NetBox Web Server", "NetBox Http Server Sample"



Sub CreatePort()

    ServerPort = 0

    Do While (ServerPort<1025 Or ServerPort>65535)

        If httpd.Create("", 0) = 0  Then

            If httpd.LocalPort > 1024 and  httpd.LocalPort < 65535 Then

                ServerPort=httpd.LocalPort

            End If

        End If

    Loop

End Sub



Sub OnServiceStart()

    Set service = Shell.Service

    If httpd.Create("", ServerPort) = 0 Then

    If b_createport = true Then

        Dim b_SaveConfig

        b_SaveConfig = Shell.MsgBox ("练习系统检测到目前分配到的端口[" & ServerPort & "]可以使用,是否保存?","保存端口",33)

        If b_SaveConfig = 1 Then

            netBox.Config("Server","Port") = ServerPort

        End If

    End If

        Set host = httpd.AddHost("", "/wwwroot")

    ‘Set host1 = host.AddFolder("WebExam","/WebExam")

        host.EnableScript = true

        host.AddDefault "default.asp"

        host.AddDefault "default.htm"

        httpd.Start

    Shell.Execute """" & NetBox.SysInfo("Folder_ProgramFiles") & "/Internet Explorer/IEXPLORE.EXE"" http://localhost:"&ServerPort&"/Your App"

    else

    Shell.MsgBox "练习系统检测到要使用的端口[" & ServerPort & "]已被别的程序占用,系统将重新分配端口!点击确定继续", "提示信息",64

    b_createport = true

    CreatePort

    OnServiceStart

    end if

End Sub



Sub OnServiceStop()

    httpd.Close

    Shell.Halt 0

    Shell.Quit 0

End Sub



Sub OnServicePause()

    httpd.Stop

End Sub



Sub OnServiceResume()

    httpd.Start

End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值