By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,142 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,142 IT Pros & Developers. It's quick & easy.

SocketServer.ThreadingTCPServer accepts clients outside server_forever

P: n/a
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))
Nov 9 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Okko Willeboordse" <tr***@willeboordse.demon.nlwrote in message
news:49**********************@dreader19.news.xs4al l.nl...
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
serve_forever() only calls accept() in a loop. clients will be able to
connect up to the backlog of the listen() call.

-Mark

Nov 9 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.