socketserver 模块

socketserver — A framework for network servers 网络服务器的框架The socketserver module simplifies the task of writing network servers.该模块简化了编写网络服务器的任务There are four basic concrete server classes: 有四种基本的具体服务...
摘要由CSDN通过智能技术生成

socketserver — A framework for network servers 网络服务器的框架

The socketserver module simplifies the task of writing network servers.该模块简化了编写网络服务器的任务

There are four basic concrete server classes: 有四种基本的具体服务器类

class socketserver.TCPServer(server_address, RequestHandlerClass, bind_and_activate=True)
它使用Internet TCP协议,该协议在客户端和服务器之间提供连续的数据流。如果bind_and_activate为true,则构造函数会自动尝试调用和 。其他参数将传递给基类

class socketserver.UDPServer(server_address, RequestHandlerClass, bind_and_activate=True)
这使用数据报,这些数据报是可能无序到达或在传输过程中丢失的离散信息包。参数与for相同。

class socketserver.UnixStreamServer(server_address, RequestHandlerClass, bind_and_activate=True)
class socketserver.UnixDatagramServer(server_address, RequestHandlerClass, bind_and_activate=True)
这些不经常使用的类类似于TCP和UDP类,但使用Unix域套接字 s; 它们不适用于非Unix平台。参数与for相同

Creating a server requires several steps. First, you must create a request handler class by subclassing the BaseRequestHandler class and overriding its handle() method; this method will process incoming requests. Second, you must instantiate one of the server classes, passing it the server’s address and the request handler class. It is recommended to use the server in a with statement. Then call the handle_request() or serve_forever() method of the server object to process one or many requests. Finally, call server_close() to close the socket (unless you used a with statement).
创建服务器需要几个步骤。首先,您必须通过继承BaseRequestHandler类并重写其handle()方法来创建请求处理程序类; 此方法将处理传入的请求。其次,您必须实例化其中一个服务器类,并将其传递给服务器的地址和请求处理程序类。建议在语句中使用服务器with。然后调用服务器对象的 handle_request()or serve_forever()方法来处理一个或多个请求。最后,调用server_close() 关闭套接字(除非你使用了一个with语句)。

Server classes have the same external methods and attributes, no matter what network protocol they use.
无论使用何种网络协议,服务器

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值