环境: 运行环境win 10
安装软件:1.Locust
2.Python2.7
实现说明:以下两上.py文件模拟实现了一个接收请求的server端一个发送请求的client端,都是本机运行
TcpSocketServer.py:(Server端代码)
# !/usr/bin/env python3
# -*- coding:utf-8 -*-
import time
from socket import socket, AF_INET, SOCK_STREAM
import threading
buffsize = 2048
def tcplink(sock, addr):
# print 'Accept new connection from %s:%s...' % addr
sock.send('Welcome!')
while True:
try:
# data = sock.recv(buffsize)
data = sock.recv(buffsize).decode()
time.sleep(1)
if data == 'exit' or not data:
break
sock.send('Hello, %s!' % data)
except Exception as e:
print(str(e))
break
s