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 3224826
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:16:06+00:00 2026-05-17T16:16:06+00:00

here is my dirty little web server : class Serverhttp: def __init__(self): self.GET =

  • 0

here is my dirty little web server :

class Serverhttp:
def __init__(self):
    self.GET = re.compile("GET.*?HTTP")
    self.POST = re.compile("POST.*?HTTP")
    try :
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server_address = ('localhost', 36000)
        print >>sys.stderr, 'starting up on %s port %s' % server_address
        sock.bind(server_address)
    except :
        time.sleep(2)
        self.__init__()
    # Listen for incoming connections
    sock.listen(1)
    off = 2
    self.message = ""
    while True:
        # Wait for a connection
        print >>sys.stderr, 'waiting for a connection'
        if off == 2 or off == 1:
            connection, client_address = sock.accept()
        try:
            print >>sys.stderr, 'connection from', client_address

            # Receive the data in small chunks and retransmit it
            while True:
                data = connection.recv(1024)
                print >>sys.stderr, 'received "%s"' % data
                if data:
                    self.message = self.traitement(data)
                    connection.sendall(self.message)
                    connection.close()
                    connection, client_address = sock.accept()

                else:
                    print >>sys.stderr, 'no more data from', client_address
                    break

        finally:
            # Clean up the connection
            connection.close()
            sock.close()
            del(sock)

it works more or less but if i quit the server the port is still open and i can’t reconnect on the same port. So i’am looking for a way to kill precedent socket or to exit in a nice way.
Regards and thanks

Bussiere

  • 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-17T16:16:07+00:00Added an answer on May 17, 2026 at 4:16 pm

    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    Should do the trick.

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

Sidebar

Related Questions

There’s a really cool diff class hosted by Google here: http://code.google.com/p/google-diff-match-patch/ I’ve used it
Here's a quick and dirty round corners technique I've been playing around with. <!--
I have some code here to call minizip(), a boilerplate dirty renamed main() of
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is what I am currently doing. PHP echo's out the recent post in
I am writing a dirty little extension method for HtmlHelper so that I can
Here is a quick and dirty GLUT based C++ program for windows that draws
given a model like: class SentenceItem < ActiveRecord::Base after_update :send_changes def send_changes #### Is
I am using the Server Side flow to get a user's permissions to access

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.