v3.7
			
			
		
		
							parent
							
								
									22c81369b5
								
							
						
					
					
						commit
						1e2f52daca
					
				| @ -0,0 +1,15 @@ | ||||
| { | ||||
|     // 使用 IntelliSense 了解相关属性。  | ||||
|     // 悬停以查看现有属性的描述。 | ||||
|     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||||
|     "version": "0.2.0", | ||||
|     "configurations": [ | ||||
|         { | ||||
|             "name": "Python: 当前文件", | ||||
|             "type": "python", | ||||
|             "request": "launch", | ||||
|             "program": "${file}", | ||||
|             "console": "integratedTerminal" | ||||
|         } | ||||
|     ] | ||||
| } | ||||
| @ -0,0 +1,6 @@ | ||||
| { | ||||
|     "python.linting.pylintEnabled": false, | ||||
|     "python.linting.pep8Enabled": true, | ||||
|     "python.linting.enabled": true, | ||||
|     "python.pythonPath": "/usr/local/bin/python3.7" | ||||
| } | ||||
| @ -0,0 +1,26 @@ | ||||
| import socketserver | ||||
| 
 | ||||
| 
 | ||||
| class TCPHandler(socketserver.StreamRequestHandler): | ||||
| 
 | ||||
|     BASE_PATH = "/Users/aria/temp/tcp/" | ||||
| 
 | ||||
|     def handle(self): | ||||
|         data = self.request.recv(1024).strip() | ||||
|         file_name = data.decode("utf-8") | ||||
|         print("file_name: %s" % file_name) | ||||
|         print("{} wrote:".format(self.client_address[0])) | ||||
|         with open(self.BASE_PATH + file_name, "rb") as f: | ||||
|             b = f.read(1024) | ||||
|             if b: | ||||
|                 self.wfile.write(b) | ||||
|             else: | ||||
|                 print("发送成功") | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
| 
 | ||||
|     HOST, PORT = "localhost", 9999 | ||||
| 
 | ||||
|     with socketserver.TCPServer((HOST, PORT), TCPHandler) as server: | ||||
|         server.serve_forever() | ||||
					Loading…
					
					
				
		Reference in new issue