1、发送报文函数:lrs_send 、lrs_length_send
直接上例子:
lrs_send ("socket5", "buf5", LrsLastArg );
第一个参数socket5是指已经建立的socket连接的名称,第二个参数buf5时需要发送的buf(在data.ws中指定)
lrs_length_send("socket0", "buf6", LeftRightBoundaries, "LB=LBoundary","RB=:RBoundary", "Offset=10", LrsLastArg);
前两个参数与lrs_send一致,第3、4、5、6个参数指定了要发送内容在buf中的位置,offset为偏移量,例如buf内容为:Start Data LBoundary & Offset:5:RBoundaryDavid
则发送报文是David
此函数适用于buf中摸个位置存在需要发送报文的长度值,比如上例中的5
注:当lrs_length_send的第三个参数指定为0时,此函数相当于lrs_send
2、接收报文函数: lrs_receive、 lrs_length_receive 、lrs_receive_ex
上例子:lrs_receive("socket1","buf1",LrsLastArg);
参数不再解释
注意:官方文档中有注释,
VuGen determines the expected size of the buffer from the recorded session. If the buffer size does not match (smaller or larger),lrs_receive rereads the incoming data carried by the socket, until the receive_timeout. By default the receive_timeout is 10 seconds. You can modify the timeout usinglrs_set_recv_timeout orlrs_set_recv_timeout2.
大致意思是如果实际收到的buf大小与录制的大小不一致,会报不匹配,并尝试重新接收,直到超时,关于此问题,我会另写一片文章。
待接收buf内容是:“12LLLL34LLLLOOOOOfffffsssssseeeeeTTTTTT9RRRRRequestedZZZZZZZZZZZZZZZZZZZZ2LLLLAAAAAAAAAAAAAAAAAAAAAAEndBuf”
lrs_length_receive("socket0", "buffer4", 2, "LB=LLLL", "RB=RRRR", "Offset=27", "Ordinal=1", LrsLastArg);
lrs_receive("socket0", "buffer5", LrsLastArg);
参数不再解释,可以参考官方文档,右边界向后数9个字节写入buffer4中,其余写入buffer5中
lrs_receive_ex("socket1", "buf2", " NumberOfBytesToRecv=10", LrsLastArg);
指定接收前10个字节。
3、关联函数:lrs_save_param、lrs_save_param_ex、lrs_save_searched_string
lrs_save_param("socket2", NULL, "param1", 67, 5);
NULL表示从最后一次接收的buf中取值,67为偏移量、5是取值长度,将取出来的内容保存到param1参数中。
lrs_save_param_ex("socket0", "received", 67,5,"ascii", "param");
此函数的主要作用是改变报文的编码格式后存入参数中
lrs_save_searched_string ("socket0", "buf1", "correlation", "LB/BIN=\\x00\\x01", "RB/BIN=\\x02", 2, 3, -1);
假如buf1中内容是:
"\x00\x01\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07Mercury\x02co\x02il\x00\x00\x01\x00\x01\xc0"
那么保存到参数correlation中的内容是 \x00\x00\x00\x07Mercury
2表示左边界出现的第二次,3表示偏移量,-1是指长度(左右边界都指定时设为-1)
以上内容为简单的函数用法,详细可参考官方文档或者在下面评论!