Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7577589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:13:36+00:00 2026-05-30T17:13:36+00:00

I need run tornado web server in a random port. Usually if a socket

  • 0

I need run tornado web server in a random port.

Usually if a socket is bind to the port 0 the os assign a random port.

import socket
s = socket.socket()
s.bind(('',0))
print s.getsockname()
('0.0.0.0', 39727)

where 39727 is the port assigned by the OS.

how can I get this behavior using tornado?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:13:37+00:00Added an answer on May 30, 2026 at 5:13 pm

    Tornado passes on the port, you can call bind_sockets with a port of 0, like this:

    import tornado.httpserver
    import tornado.ioloop
    import tornado.netutil
    import tornado.web
    
    app = tornado.web.Application()
    sockets = tornado.netutil.bind_sockets(0, '')
    server = tornado.httpserver.HTTPServer(app)
    server.add_sockets(sockets)
    
    for s in sockets:
        print('Listening on %s, port %d' % s.getsockname()[:2])
    tornado.ioloop.IOLoop.instance().start()
    

    Note that you’ll get different port numbers for IPv4 and IPv6. If you want IPv4 and IPv6 to be on the same port, either try port numbers yourself, or supply a list with your own socket created as in the question (create an IPv6 socket with IPV6_V6ONLY set to 0 to get both IPv6 and IPv4 on the same socket) in the place of sockets in the above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've set up a Flask application to run on a tornado server backed by
we need run one function periodically in Java web application . How to call
What are the web-based clients for XMPP/Jabber. I need run IM client in browser
I'm trying to write a simple python web application using the Tornado web server
I need to run a stored procedure on SQL Server, using LINQ, and throw
I need to run a job in a scheduled manner, on tomcat server deployed
i need run code that will create a database and populate tables. i am
I need to run a JavaScript function onLoad(), but only do it if the
I need to run a stored procedure from a C# application. I use the
I need to run an equipment audit and to do that I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.