jmeter
1.java
AudioSystem.getAudioInputStream(File)
到底如何转换??
java sound
- beanshell 预处理
vars.put("bytes", s);
ws write
${bytes}
暂时失败告终,有空再学习.....
python websocket-client
对jmeter 实在是不怎么熟悉,先用比较熟悉的python 实现一下吧。
短连接
import websocket
ws = websocket.WebSocket()
ws.connect(url)
ws.send("123")
print(ws.recv())
ws.close()
长连接
import websocket
def on_message(ws,message):
print(message)
# 这里的ws必须和on_message的ws同名
ws = websocket.WebSocketApp(url,on_message=on_message)
ws.run_forever()
debug 和 日志选项
websocket.enableTrace(True)
WebSocketApp init 参数详解
__init__(url, header=None, on_open=None, on_message=None, on_error=None, on_close=None, on_ping=None, on_pong=None, on_cont_message=None, keep_running=True, get_mask_key=None, cookie=None, subprotocols=None, on_data=None)
header: 自定义头部
简要实现
import websocket
import json
from pprint import pprint
from websocket import ABNF
try:
import thread
except ImportError:
import _thread as thread
import time
USER_NAME = "PythonTest"+str(time.time())
DEFAULT_WAITTIME =3
def sendWAV(ws):
print("============开始发送音频数据==================")
step = 3200
with open("./test.wav", ‘rb‘) as f:
while True:
read_data = f.read(step)
if read_data:
ws.send(read_data, ABNF.OPCODE_BINARY)
if len(read_data) < step:
break
setWaiting(0.1)
print("============结束发送音频数据================")
def setWaiting(waiting_time=DEFAULT_WAITTIME):
if waiting_time == 0.1: return
print("等待时间:"+str(waiting_time)+"s")
time.sleep(waiting_time)
def writeRespFile(message):
with open("./responsemessage.txt","a+") as foo:
current_time = str(time.asctime( time.localtime(time.time()) ))
foo.write("【"+current_time+"】")
foo.write("\n\n")
foo.write(message)
foo.write("\n\n")
def sendData(ws,user_id):
print("\n==========开始发送数据=============")
sendWAV(ws)
ws.send("test")
ws.close()
print("\n=============发送数据完成==========")
def on_message(ws, message):
writeRespFile(message)
print("【server message】\n"+message)
sendData(ws,user_id)
def on_error(ws, error):
print(error)
print("!!!!!!!!!发生未知错误!!!!!!!!!\n关闭连接........\n")
ws.close()
def on_close(ws):
print("===== closed =======\n")
def on_ping(ws,message):
print("客户端发送ping")
print(message)
def on_pong(ws,message):
print("客户端接收pong:")
print(message)
def on_open(ws):
def run(*args):
print("【已建立连接......】\n")
data={
"user_name":USER_NAME
}
ws.send(json.dumps(data))
setWaiting()
thread.start_new_thread(run, ())
def test_run():
websocket.enableTrace(True)
global user_id
user_id = ""
global ws
ws = websocket.WebSocketApp(url,
on_open = on_open,
on_message = on_message,
on_error = on_error,
on_close = on_close,
on_ping=on_ping,
on_pong=on_pong)
ws.run_forever(ping_interval=10,ping_timeout=3)
js
https://github.com/websockets/ws
https://blog.csdn.net/qq_32252957/article/details/88586497
electron 打包成exe
https://github.com/electron/electron