SocketServer.ThreadingTCPServer accepts clients outside server_forever

  • Thread starter Okko Willeboordse
  • Start date
O

Okko Willeboordse

Hello,

SocketServer.ThreadingTCPServer accepts connections (clients can
connect) before and after it's server_forever method is called,
see below for an example.

IMHO it should only accept connections while server_forever is
running.

Kind regards,

Okko

Example, both _socket.connect calls should throw;

import SocketServer
import threading
import time
import socket

server = SocketServer.ThreadingTCPServer(("127.0.0.1", 12345),
SocketServer.BaseRequestHandler)

_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

_socket.connect(("127.0.0.1", 12345))

def shutdown_server():
while not server._BaseServer__serving:
time.sleep(0.1)
server.shutdown()

thread = threading.Thread(target = shutdown_server)
thread.start()

server.serve_forever()
thread.join()

_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

_socket.connect(("127.0.0.1", 12345))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top