WinSocket script writing examples and explanations

Source: Internet
Author: User

We know that the WinSocket script is not the same as the Web (HTML) script, and the Web (HTML) script is modeled primarily with the HTML protocol, which is scripted according to the interface provided by the developer. And the WinSocket protocol is mainly based on the internal communication protocol used by the server and the client (internal communication protocol, what we are talking about is a custom communication protocol) script, so we need to use the tool has the Network capture tool Wireshark and understand the content and role of the internal communication Protocol, We can also through the server and client communication Log view (Linux we can through Tail-f/var/log/tomcat ... View logs). All right, let's get moving!

The first step is of course the new WinSocket protocol:

I would like to add a few points of knowledge before writing the script:

1. Network byte sequence and host byte order http://blog.csdn.net/houwei544/article/details/8592996

Conversion Mode:

2, 8 bytes of 16 binary (with X-header): Message type 4 bytes + message body Content length 4 bytes, the binary type is generally defined by developers

3. The escape character "\" in the C language is used to enter special characters, such as \ "

The second step is to write the script, refer to the literature http://www.ltesting.net/ceshi/ceshijishu/rjcsgj/mercury/loadrunner/2013/0106/205871.html

Four parts:

First we want to create sockets, such as Lrs_create_socket ("Socket1", "TCP", "localhost=172.16.0.2:1202", "remotehost=172.16.255.254:6002", LRSLASTARG);

Then we can send data and receive data such as Lrs_send ("Socket1", "buf1001", Lrslastarg); Lrs_receive ("Socket1", "buf2001", Lrslastarg);

Second, we write data data files based on packet capture or server-to-client communication logs, which can be provided by the developer with an internal communication protocol specification:

; Wsrdata 2 1


Send buf1001 79
"\xe9\x03\x00\x00\x47\x00\x00\x00"//8 bytes of 16 binary: Message type 1001+ message body content length 71 bytes
"B0-51-8E-08-74-93;172.16.0.2;EMPTY;0;0; A5F5BE704C7447E68E7F8D5F810C0C31 "//message body content, 71 bytes in length
Recv buf2001 17
"\xd1\x07\x00\x00\x09\x00\x00\x00"
"Success;1"

-1

Clutch results:

We know that the Decimal 1001 protocol type is converted to 16 binary equals 3e9, the message body content length is 71 to 16 binary equals 47

Then we convert 3e9 to network byte order is e9030000, convert 47 to network byte order is 47000000 (complement 0), so we can see the above result by grasping the packet.

Server and client communication logs:

Finally we close the socket, such as Lrs_close_socket ("Socket1");

WinSocket script writing examples and explanations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.