For python 2:
For python 3:
If port number is not given 8000 is the default port. So
the output will be:
Serving HTTP on 0.0.0.0 port 8000 ...
You can access to your files through any device connected to the local network by typing http://hostipaddress:8000/.
hostipaddress is your local ip address which probably starts with 192.168.x.x.
To finish the module simply press ctrl+c.
Creating a TCP server
You can create a TCP server using the socketserver library.
Here's a simple echo server.
socketserver makes it relatively easy to create simple TCP servers. However, you
should be aware that, by default, the servers are single threaded and can only serve one client at a time. If you want to handle multiple clients, either instantiate a ThreadingTCPServer instead.
Creating a UDP Server
A UDP server is easily created using the socketserver library.
a simple time server:
Start Simple HttpServer in a thread and open the browser
Useful if your program is outputting web pages along the way.
The simplest Python socket client-server example
First run the SocketServer.py, and make sure the server is ready to listen/receive sth
Then the client send info to the server;
After the server received sth, it terminates
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0