Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 failed #36

Open
jerrygzy opened this issue Oct 26, 2024 · 0 comments
Open

IPv6 failed #36

jerrygzy opened this issue Oct 26, 2024 · 0 comments

Comments

@jerrygzy
Copy link

jerrygzy commented Oct 26, 2024

import options, asyncdispatch
import httpx, net

proc onRequest(req: Request): Future[void] {.async.} =
  # Log the incoming request
  echo "Received request: ", req.httpMethod.get(), " ", req.path

  if req.httpMethod == some(HttpGet):
    case req.path.get()
    of "/":
      req.send("Hello World")
      echo "Sent response: Hello World"
    else:
      req.send(Http404)
      echo "Sent response: 404 Not Found"

let settings = Settings(
  port: Port(80),
  bindAddr: "::",  # IPv6 address
  listener: newSocket(AF_INET6, SOCK_STREAM, IPPROTO_IPV6)
)

# Start the server and log that it's running
echo "Starting server on port ", settings.port
run(onRequest, settings)
echo "Server is running"

error

/Users/of/Work/Nim/web_test/ssr_test/src/serverv6.nim(22) serverv6
/Users/of/.choosenim/toolchains/nim-2.2.0/lib/pure/net.nim(309) newSocket
/Users/of/.choosenim/toolchains/nim-2.2.0/lib/std/oserrors.nim(92) raiseOSError
Error: unhandled exception: Bad file descriptor [OSError]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant