Open jongpak opened 5 years ago
import socket import select import time server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server.bind(('127.0.0.1', 1234)) server.listen(0) print('listen...') while True: read_socket_list, _, _ = select.select([server], [], []) for read_socket in read_socket_list: start = time.time() time.sleep(3) client, _ = read_socket.accept() print('accept => ' + str(time.time() - start)) client.send(b'HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nSleep') time.sleep(5) client.close() print('close => ' + str(time.time() - start))
const request = require('request'); request('http://127.0.0.1:1234', { timeout: 4000 }, function(error, resp, body) { if (error) { console.error(error); } else { console.log(body); } });
Server
client