Skip to content

Will not run on designated port #1

@code-monki

Description

@code-monki

Windows 11

Command:

winhttpd.exe "...." --addr "localhost" --port 10001

Description of Problem:

Server starts and reports it is listening on port 80, not 10001. Also fails to serve any pages.

Using localhost also returns a malformed addr error.

Using 127.0.0.1 results in a Windows firewall error and was part of a security issue due to the hosts /etc/hosts file being world-writable.

I am distributing the binary with a collection of web pages and need to be able to let the end-user access the pages on their local machine. Most of the users are not computer-savvy, hence the restriction. I am trying to use the following batch file to launch winhttpd in the background and the launch a browser instance pointing at the index.html in the webroot.

@echo off
setlocal EnableDelayedExpansion

::Configuration
set "ADDRESS=localhost"
set "PORT=10001"
set "BINPATH=.\windows"
set "BINARY=winhttpd.exe"
set "WEBROOT=..\"
set "EXITSERVER=1"

echo Launching web server at http://%ADDRESS%:%PORT%

:: Start the server in background
start "" "%BINPATH%\%BINARY%" %WEBROOT% --addr %ADDRESS% --port %PORT%

:: Open default browser
start "" http://%ADDRESS%:%PORT%

::Wait loop
:wait_for_exit
echo .
echo Press CTRL+C to shut down the server
ping 127.0.0.1 -n 2 > nul
goto wait_for_exit

:: Cleanup
:shutdown
echo .
echo Attempting to shut down the server...

::Kill process based on PID
taskkill /IM winhttpd.exe /F /T
exit

I may well be doing something wrong in the batch file, but I get the errors above when I run the command listed from the command line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions