Python成长笔记 - 基础篇 (九)

创建一个socketserver 至少分以下几步:
  1. First, you must create a request handler class by subclassing the BaseRequestHandlerclass and overriding its handle() method; this method will process incoming requests.   
  2. Second, you must instantiate one of the server classes, passing it the server’s address and the request handler class.
  3. Then call the handle_request() orserve_forever() method of the server object to process one or many requests.
  4. Finally, call server_close() to close the socket.
 
1、自己创建一个请求处理类,
2、自己实例化一个TCP server ,并且传递server ip 和你上面创建的请求处理类
3、
 
 
 
import socketserver
 
class MyTCPHandler(socketserver.BaseRequestHandler):
"""
The request handler class for our server.
 
It is instantiated once per connection to the server, and must
override the handle() method to implement communication to the
client.
"""
 
def handle(self):
# self.request is the TCP socket connected to the client
while True:
try:
self.data = self.request.recv(1024).strip()
print("{} wrote:".format(self.client_address[0]))
print(self.data)
self.request.send(self.data.upper())
except ConnectionAbortedError as e:
print("err",e)
break
 
if __name__ == "__main__":
HOST, PORT = "localhost", 1111
 
# Create the server, binding to localhost on port 9999
server = socketserver.ThreadingTCPServer((HOST, PORT), MyTCPHandler)
server.serve_forever()
 
 
 
 
ThreadingTCPServer支持多线程
 
 
 
 
 
4、每个用户单独字典
5、在linux上运行
 
7、mod5验证
8、百分比
9、断点续传:暂停时将已传文件大小(字节)存在临时文件中,续传时读取临时文件
 

转载于:https://www.cnblogs.com/huangmx-amin/p/5877995.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值