我正在尝试使用 golang 在 Windows 计算机上的不同端口上启动多个服务器。这是出于内部测试目的。
所以最终结果是有一个可执行文件,它将在多个端口上启动我的服务器的多个实例(另一个 Windows 可执行文件)。我理想的方法是让“n”个 go 例程在从“port+0”到“port+n”的端口上启动命令“myserver.exe .\config.json port+n”,这样我就可以“ n" 服务器已启动并正在运行。我正在想办法启动我的服务器并继续监听,直到我希望程序结束。
我的服务器是一个 Windows 可执行文件,它在启动它时提到的端口上运行。当我手动启动它时它工作正常。它可以启动为:
C:\Install\myServer.exe C:\Install\Configuration.json 8079
上面的命令启动服务器并侦听端口 8079。我想在不同端口上启动同一服务器的多个实例。我按照 golang 程序编写的代码不适用于 Windows 服务,https://github.com/kardianos/service如下。我可以看到启动服务器的命令已执行,但当我打开 services.msc 时,我看不到任何服务,当我执行 get-service powershell 命令时,我也看不到任何服务。我还尝试在通过 go 程序启动后查看是否可以监听端口 8079(在本例中),看看是否得到任何响应,但出现以下错误:
panic: Get http://localhost:8079/config: dial tcp [::1]:8079: connectex: No connection could be made because the targetmachine actively refused it.
上述代码的输出:
Main Run
Creating the command C:\Install\myServer.exe C:\Install\Configuration.json 8079
Starting the command
out: Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
跃然一笑
相关分类