高手的存在,就是让服务10亿人的时候,你感觉只是为你一个人服务......

lrs_set_recv_timeout 解决长连接等待

目录

最近又碰到坑爹的通讯项目,web端登录与客户端登录消息用的一套长连接机制。
脚本写的真是蛋疼、累死,不仅要用socket协议,还要模拟长连接接收消息,最后要看一堆无语的data.ws文件。
而且,两个部门协作起来真是无力吐槽了!
还好有lrs_set_recv_timeout

lrs_set_recv_timeout有两个函数
lrs_set_recv_timeout和lrs_set_recv_timeout2

lrs_set_recv_timeout(long sec, long u_sec); // 设置接收数据的等待时间(超时时间)
lrs_set_recv_timeout2(long sec, long u_sec); // 设置建立连接成功之后,接收数据的等待时间。

Example:

lrs_create_socket(“socket2”, “TCP”,
“RemoteHost=tears.mercury.co.il:23”, LrsLastArg); lrs_send(“socket2”,
“buf2”, LrsLastArg); lrs_set_recv_timeout(120,0);
lrs_set_recv_timeout2(10,0); lrs_receive(“socket2”, “buf3”,
LrsLastArg);

我的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*********************************************************************
* Created by Mercury Interactive Windows Sockets Recorder
*
* Created on: Tue Oct 27 17:48:09
*********************************************************************/

#include "lrs.h"
...
char *position;
char *position2;
Action()
{
lrs_create_socket("socket0", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);
//GET mictouch_logout HTTP1.1 Host: m.made-in-china.com
lrs_send("socket0", "buf0", LrsLastArg);

lrs_receive("socket0", "buf1", LrsLastArg);
//location: /login
lrs_send("socket0", "buf2", LrsLastArg);

lrs_receive("socket0", "buf3", LrsLastArg);

lrs_create_socket("socket1", "TCP", "RemoteHost=192.168.17.54:80", LrsLastArg);

lrs_create_socket("socket2", "TCP", "RemoteHost=192.168.17.54:80", LrsLastArg);
//GET /mt/img/phone.svg?_v=1445919622415 HTTP/1.1\r\n
lrs_send("socket1", "buf4", LrsLastArg);

lrs_create_socket("socket3", "TCP", "RemoteHost=192.168.17.54:80", LrsLastArg);

lrs_receive("socket1", "buf5", LrsLastArg);

lrs_create_socket("socket4", "TCP", "RemoteHost=192.168.17.54:80", LrsLastArg);

lrs_create_socket("socket5", "TCP", "RemoteHost=192.168.17.54:80", LrsLastArg);

lrs_create_socket("socket6", "TCP", "RemoteHost=192.168.17.54:80", LrsLastArg);

lrs_create_socket("socket7", "TCP", "RemoteHost=192.168.17.54:80", LrsLastArg);

lrs_create_socket("socket8", "TCP", "RemoteHost=203.208.40.135:80", LrsLastArg);


lrs_close_socket("socket0");

lrs_create_socket("socket9", "TCP", "RemoteHost=203.208.40.135:80", LrsLastArg);

lrs_close_socket("socket4");

lrs_close_socket("socket2");

lrs_close_socket("socket3");

lrs_close_socket("socket6");

lrs_close_socket("socket5");

lrs_close_socket("socket7");

lrs_close_socket("socket9");

lrs_close_socket("socket8");

lrs_create_socket("socket10", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);
//GET /favicon.ico HTTP/1.1\r\n"

lrs_send("socket10", "buf7", LrsLastArg);

lrs_create_socket("socket11", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);

lrs_receive("socket10", "buf8", LrsLastArg);
//POST /mictouch_login HTTP/1.1\r\n"


lrs_send("socket10", "buf9", LrsLastArg);

lrs_receive("socket10", "buf10", LrsLastArg);

lrs_send("socket11", "buf11", LrsLastArg);

lrs_receive("socket11", "buf12", LrsLastArg);

lrs_create_socket("socket12", "TCP", "RemoteHost=192.168.17.54:80", LrsLastArg);

lrs_create_socket("socket13", "TCP", "RemoteHost=203.208.40.135:80", LrsLastArg);


lrs_create_socket("socket14", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);

///tm/leaveword/count.jsonp?domainUserId=CdekVYuGXQJi_00&domain=micen&ca
lrs_send("socket14", "buf16", LrsLastArg);

lrs_create_socket("socket15", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);

lrs_receive("socket14", "buf17", LrsLastArg);

lrs_close_socket("socket10");

lrs_close_socket("socket12");

lrs_close_socket("socket11");

lrs_close_socket("socket14");

lrs_close_socket("socket15");

lrs_close_socket("socket13");

lr_start_transaction("login----------------------");

lrs_create_socket("socket16", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);

lrs_create_socket("socket17", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);
//GET /favicon.ico
lrs_send("socket16", "buf18", LrsLastArg);
//GET /webtm/contacts
lrs_send("socket17", "buf19", LrsLastArg);
lrs_set_recv_timeout2(15,0);



lr_start_transaction("1");

lrs_set_receive_option(EndMarker, StringTerminator , "HTTP/1.1");
lrs_receive("socket16", "buf20", LrsLastArg);

lr_end_transaction("1", LR_AUTO);

lrs_set_recv_timeout2(15,0);


lr_start_transaction("2");

lrs_receive("socket17", "buf21", LrsLastArg);


lr_end_transaction("2", LR_AUTO);

//GET /mt/webim/dist/css/webim.css?v=1444877296783 HTTP/1.1\r\n
lrs_send("socket1", "buf22", LrsLastArg);
lrs_set_recv_timeout2(15,0);

lr_start_transaction("3");

lrs_receive("socket1", "buf23", LrsLastArg);


lr_end_transaction("3", LR_AUTO);

//GET /mt/webim/dist/js/webim.js?v=1444877296783
lrs_send("socket1", "buf24", LrsLastArg);
lrs_set_recv_timeout2(15,0);

lr_start_transaction("4");

lrs_receive("socket1", "buf25", LrsLastArg);

lr_end_transaction("4", LR_AUTO);

lrs_create_socket("socket18", "TCP", "RemoteHost=203.208.40.135:80", LrsLastArg);


lrs_create_socket("socket19", "TCP", "RemoteHost=192.168.17.54:80", LrsLastArg);

lrs_create_socket("socket20", "TCP", "RemoteHost=203.208.40.135:80", LrsLastArg);

lrs_create_socket("socket21", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);

lrs_create_socket("socket22", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);
//GET /connect?callback=jQuery21406809277604824309_1445939283967&_=144593928
lrs_send("socket21", "buf27", LrsLastArg);
lrs_set_recv_timeout2(15,0);
lrs_set_receive_option(EndMarker, StringTerminator , ":15");

lr_start_transaction("5");

lrs_receive("socket21", "buf28", LrsLastArg);

lr_end_transaction("5", LR_AUTO);

//GET /webtm/getauth/?callback=jQuery21406809277604824309_1445939283967&_=14

lrs_create_socket("socket23", "TCP", "RemoteHost=webserver.trademessenger.com:80", LrsLastArg);

lrs_send("socket23", "buf29", LrsLastArg);
//GET /connect?callback=jQuery21406809277604824309_1445939283970&s=fc90b31b1
lrs_send("socket21", "buf30", LrsLastArg);
lrs_set_recv_timeout2(60,0);
lrs_set_receive_option(EndMarker, StringTerminator , "username");

lr_start_transaction("6");

lrs_set_receive_option(EndMarker, StringTerminator , "HTTP/1.1");
lrs_receive("socket23", "buf31", LrsLastArg);

lr_end_transaction("6", LR_AUTO);

lrs_send("socket22", "buf32", LrsLastArg);
lrs_set_recv_timeout2(15,0);
lrs_set_receive_option(EndMarker, StringTerminator , "jQuery");

lr_start_transaction("7");

lrs_receive("socket22", "buf33", LrsLastArg);

lr_end_transaction("7", LR_AUTO);

lrs_set_receive_option(EndMarker, StringTerminator , "LoginReq");
lrs_set_recv_timeout2(15,0);

lr_start_transaction("8");

lrs_receive("socket21", "buf34", LrsLastArg);

lr_end_transaction("8", LR_AUTO);

lrs_send("socket21", "buf35", LrsLastArg);

// lrs_save_param_ex("socket21","received",NULL,200,400,NULL,"Param_Received");
// lr_output_message(lr_eval_string("<Param_Received>"));
lrs_set_recv_timeout2(15,0);
lrs_set_receive_option(EndMarker, StringTerminator , "plantData");
lrs_receive("socket21", "buf36", LrsLastArg);


// position =(char*) strstr(lr_eval_string("<Param_Received>"),lr_eval_string("LoginReq"));
// position2 =(char*) strstr(lr_eval_string("<Param_Received>"),lr_eval_string("plantData"));
// if(position==NULL&&position2==NULL)
//lr_end_transaction("login----------------------", LR_FAIL);


lr_end_transaction("login----------------------", LR_AUTO);


lrs_close_socket("socket16");
lrs_close_socket("socket17");
lrs_close_socket("socket18");
lrs_close_socket("socket19");
lrs_close_socket("socket20");
lrs_close_socket("socket21");
lrs_close_socket("socket22");
lrs_close_socket("socket23");
return 0;
}