#! /usr/bin/python2.7 # -*- coding: utf-8 -*- from http import HttpServer resources = { 'not_found': {'html': "<h1>Not Found</h1>Sorry, no such resource."}, '/': {'html': '<h1>Home</h1>Home page'}, '/about': {'html':'<h1>About</h1>All about me'}, '/bunny': {'html': 'My html new'}, } s = HttpServer('8030', resources) s.run()
from socket import * import socket import threading import time import sys import logging from http import HttpServer httpserver = HttpServer() class ProcessTheClient(threading.Thread): def __init__(self, connection, address): self.connection = connection self.address = address threading.Thread.__init__(self) def run(self): rcv = "" while True: try: data = self.connection.recv(32) if data: d = data.decode() rcv = rcv + d if rcv[-2:] == '\r\n': #end of command, proses string logging.warning("data dari client: {}".format(rcv)) hasil = httpserver.proses(rcv) hasil = hasil + "\r\n\r\n" logging.warning("balas ke client: {}".format(hasil))