Foundations of Python Network Programming 2nd edition phần 5

mà bạn nghĩ có thể tốt hơn là mã với cộng đồng lớn hơn có nhiều khả năng có điểm yếu và lỗ hổng phát hiện và giải quyết. Giữ tất cả mọi thứ nâng cấp và up-to-ngày khi có thể, từ hệ thống điều hành và cài đặt Python của bạn để phân phối cụ thể bạn đang sử dụng của PyPI. Và, tất nhiên, | CHAPTER 7 SERVER ARCHITECTURE The tcpd binary would read the etc and files and enforce any access rules it found there and also possibly log the incoming connection before deciding to pass control through to the actual service being protected. If you are writing a Python service to be run from inetd the client socket returned by the inetd accept call will be passed in as your standard input and output. If you are willing to have standard file buffering in between you and your client and to endure the constant requirement that you flush the output every time that you are ready for the client to receive your newest block of data then you can simply read from standard input and write to the standard output normally. If instead you want to run real send and recv calls then you will have to convert one of your input streams into a socket and then close the originals because of a peculiarity of the Python socket fromfd call it calls dup before handing you the socket so that you can close the socket and file descriptor separately import socket sys sock In this sense inetd is very much like the CGI mechanism for web services it runs a separate process for every request that arrives and hands that program the client socket as though the program had been run with a normal standard input and output. Summary Network servers typically need to run as daemons so that they do not exit when a particular user logs out and since they will have no controlling terminal they will need to log their activity to files so that administrators can monitor and debug them. Either supervisor or the daemon module is a good solution for the first problem and the standard logging module should be your focus for achieving the second. One approach to network programming is to write an event-driven program or use an event-driven framework like Twisted Python. In both cases the program returns .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.