python socketserver连接数量限制_python中socketserver的一个疑问

书上代码如下:

一个基于sockerserver的小型服务器

from socketserver import TCPServer,StreamRequestHandler

class Handler(StreamRequestHandler):

def handle(self):

print(type(self.request))

addr = self.request.getpeername()

print('Got connection from ',addr)

self.wfile.write(b'thank you for connecting...')

server = TCPServer(('li-linfeng1',1234),Handler)

server.serve_forever()

我的问题是,Handler中的self.request为什么是一个socket对象呢?

self.request所在的类BaseRequestHandler源代码如下,从源代码中也看不出self.request是socket对象,求问是怎么知道这个self.request是socket对象,从而可以调用getpeername()方法的呢?

class BaseRequestHandler:

"""Base class for request handler classes.

This class is instantiated for each request to be handled. The

constructor sets the instance variables request, client_address

and server, and then calls the handle() method. To implement a

specific service, all you need to do is to derive a class which

defines a handle() method.

The handle() method can find the request as self.request, the

client address as self.client_address, and the server (in case it

needs access to per-server information) as self.server. Since a

separate instance is created for each request, the handle() method

can define arbitrary other instance variariables.

"""

def __init__(self, request, client_address, server):

self.request = request

self.client_address = client_address

self.server = server

self.setup()

try:

self.handle()

finally:

self.finish()

def setup(self):

pass

def handle(self):

pass

def finish(self):

pass

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值