|
例子:
/****************************************************************
*****
* 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 编辑 ] |
|