NetBox creates Unity local server

## Preface

* After looking through a lot of tutorials on the Internet, I copied this and that and copied this back and forth to explain it, so I didn’t understand it, so I just wrote it myself

## steps

1. Download netbox and unzip it

2. Choose any place to create a folder named WebServer as your own local server

3. Copy NetBox.exe to the WebServer folder, as shown in the figure

 4. Create a txt text file and modify the suffix to box, which is the exclusive suffix of netbox files. Open the main.box file just created in Notepad and fill in the following code:

Dim httpd
Shell.Service.RunService "NBWeb", "NetBox Web Server", "NetBox Http Server Sample"
'---------------------- Service Event ---------------------
Sub OnServiceStart()
      Set httpd = NetBox.CreateObject("NetBox.HttpServer")
      If httpd.Create("", 84) = 0 Then
            Set host = httpd.AddHost("", "/wwwroot")
            host.EnableScript = true
            host.AddDefault "index.htm"
            host.AddDefault "index.html"
            host.AddDefault "1.asp"
            httpd.Start
     else
           Shell.Quit 0
           end if
     End Sub

Sub OnServiceStop()
      httpd.Close
End Sub

Sub OnServicePause()
     httpd.Stop
End Sub

Sub OnServiceResume()
      httpd.Start
End Sub

### Points to note

1. NexBox.CreateObject

2. 84 is the open port of the computer, and it can also be changed to other numbers. We will access the local area later through this port, such as 8080, 80, 81, 84, etc.

3. There must be a file and syntax under the WebServer folder

wwwroot has the same name as the root directory of the website

4. The website opened by default, at this time, enter localhost:port number in the browser address bar

Mine is 84, then enter localhost:84 and press Enter to open, you will find that it is rejected, because the netbox server has not been opened

5. Double-click NetBox.exe in the WebServer folder, then double-click main.box, and an icon will appear in the lower right corner of the computer

 6. At this time, visit localhost:84 again, and the visit is successful

 

Guess you like

Origin blog.csdn.net/SuShengQuanshiW/article/details/127292551