File tree Expand file tree Collapse file tree 1 file changed +19
-13
lines changed Expand file tree Collapse file tree 1 file changed +19
-13
lines changed Original file line number Diff line number Diff line change 2
2
import http .server
3
3
import socketserver
4
4
5
- # tasklist
6
- # /IM py37.exe /F
7
- #
8
- hostname = socket .gethostname ()
9
- PORT = 8000
10
- IP = socket .gethostbyname (hostname )
5
+ def get_server_address ():
6
+ """Returns the server's IP address and port."""
7
+ hostname = socket .gethostname ()
8
+ ip = socket .gethostbyname (hostname )
9
+ return ip , 8000
11
10
12
- Handler = http .server .SimpleHTTPRequestHandler
13
- with socketserver .TCPServer (("" , PORT ), Handler ) as httpd :
14
- print (f"Serving on: { IP } :{ PORT } " )
15
- try :
16
- httpd .serve_forever ()
17
- except KeyboardInterrupt :
18
- print ("Shutting down serve.py..." )
11
+ def run_server ():
12
+ """Runs the HTTP server."""
13
+ ip , port = get_server_address ()
14
+ handler = http .server .SimpleHTTPRequestHandler
15
+
16
+ with socketserver .TCPServer (("" , port ), handler ) as httpd :
17
+ print (f"Serving on: { ip } :{ port } " )
18
+ try :
19
+ httpd .serve_forever ()
20
+ except KeyboardInterrupt :
21
+ print ("Shutting down server..." )
22
+
23
+ if __name__ == "__main__" :
24
+ run_server ()
You can’t perform that action at this time.
0 commit comments