Tutorial by Examples

Server side: import socket serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serversocket.bind(('localhost', 8089)) serversocket.listen(5) # become a server socket, maximum 5 connections while True: connection, address = serversocket.accept() buf = connection.recv(6...
To share files or to host simple websites(http and javascript) in your local network, you can use Python's builtin SimpleHTTPServer module. Python should be in your Path variable. Go to the folder where your files are and type: For python 2: $ python -m SimpleHTTPServer <portnumber> For p...
You can create a TCP server using the socketserver library. Here's a simple echo server. Server side from sockerserver import BaseRequestHandler, TCPServer class EchoHandler(BaseRequestHandler): def handle(self): print('connection from:', self.client_address) while True:...
A UDP server is easily created using the socketserver library. a simple time server: import time from socketserver import BaseRequestHandler, UDPServer class CtimeHandler(BaseRequestHandler): def handle(self): print('connection from: ', self.client_address) # Get message and cli...
Useful if your program is outputting web pages along the way. from http.server import HTTPServer, CGIHTTPRequestHandler import webbrowser import threading def start_server(path, port=8000): '''Start a simple webserver serving path on port''' os.chdir(path) httpd = HTTPServer((''...

Page 1 of 1