51Testing软件测试论坛
标题:
如何把buf里收到的端口号作为action里的UDP连接send目标?
[打印本页]
作者:
basler
时间:
2006-7-17 17:12
标题:
如何把buf里收到的端口号作为action里的UDP连接send目标?
socket脚本,客户端先用tcp与服务器连接,有服务器处获得一随机端口号,然后再用udp与服务器的这一随机端口号连接(其实是realplayer和server)。怎么才能把分别在buf和脚本里的两个东西联系起来啊。设关联吗?设完之后,并不能影响action.c文件啊,恳请高手指教。
[
本帖最后由 basler 于 2006-7-18 10:48 编辑
]
作者:
basler
时间:
2006-7-18 09:30
急需指教,请前辈教教我,万分感谢
作者:
Zee
时间:
2006-7-18 09:55
例子:
/****************************************************************
*****
* Created by Mercury Interactive Windows Sockets Recorder
* Created on: Sat Apr 15 21:55:23
*****************************************************************
****/
#include "lrs.h"
Actions ()
{
char *NewPort;
char *UserBuf;
char Buf[255];
char Tmp[255];
int iVal, iHighVal, iLowVal;
lr_think_time(12);
lrs_send("socket2", "buf8", LrsLastArg);
lrs_receive("socket2", "buf9", LrsLastArg);
lrs_create_socket("socket3", "TCP", "LocalHost=0",
"Backlog=1", LrsLastArg);
/* 在socket3中得到本地主机的端口 */
NewPort = lrs_get_socket_attrib("socket3", LOCAL_PORT );
lr_output_message("Local port %s", NewPort);
/* Parse NewPort to low and high order and save to 'PortNum'
parameter */
iVal = atoi (NewPort);
iLowVal = (WORD)(iVal) & 0xFF;
iHighVal = (WORD)(((DWORD)(iVal) >> 8) & 0xFF);
strcpy (Buf, itoa( iHighVal, Tmp, 10 ));
strcat (Buf, ",");
strcat (Buf, _itoa( iLowVal, Tmp, 10 ));
/* Save the PortNum to buf 10.
* send buf10
* "PORT 199,203,74,132,<PortNum>\r\n"
* The first 4 numbers are the IP and the fifth argument must
be
* replaced with the new parameter.*/
lr_save_string(Buf, "PortNum");
/* Get the content of Buf10 and print to output for debug */
lrs_get_static_buffer("socket2", "buf10", 0, -1, NULL);
UserBuf = lrs_get_user_buffer("socket2");
lr_output_message("Buf10 Content %s", UserBuf);
lrs_send("socket2", "buf10", LrsLastArg);
lrs_receive("socket2", "buf11", LrsLastArg);
lrs_send("socket2", "buf12", LrsLastArg);
lrs_receive("socket2", "buf13", LrsLastArg);
lrs_set_accept_timeout(30,0);
lrs_accept_connection("socket3", "socket4");
lrs_close_socket("socket3");
lrs_receive("socket4", "buf14", LrsLastArg);
lrs_close_socket("socket4");
lrs_receive("socket2", "buf15", LrsLastArg);
return 0;
}
[
本帖最后由 Zee 于 2006-7-18 09:58 编辑
]
作者:
basler
时间:
2006-7-18 10:06
多谢版主了,帮大忙了
作者:
basler
时间:
2006-7-18 10:37
lrs_get_socket_attrib得到的端口应该是从作为参数的socket处得到的。
我的意思是,怎么把一个soket里receive到的buf的值,作为另一个UDPsoket,send里的参数
buf5里receive到的
“..client_port=6970;server_port=31558\r\n\r\n”
发送udp的soket
lrs_create_socket("socket1", "UDP", "LocalHost=6970", LrsLastArg);
lrs_send("socket1", "buf6", "TargetSocket=172.20.23.20:31558", LrsLastArg);
作者:
Zee
时间:
2006-7-18 10:53
用lr_eval_string试试。
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2