Added a TCPServer stress test utility developed with the SFML
This commit is contained in:
parent
e5733b88cc
commit
8191aa640b
42
src/software_test/ESP8266TCPStresser/ESP8266TCPStresser.cbp
Normal file
42
src/software_test/ESP8266TCPStresser/ESP8266TCPStresser.cbp
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="ESP8266TCPStresser" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/ESP8266TCPStresser" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/ESP8266TCPStresser" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="main.cpp" />
|
||||
<Extensions>
|
||||
<code_completion />
|
||||
<envvars />
|
||||
<debugger />
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
@ -0,0 +1,7 @@
|
||||
# depslib dependency file v1.0
|
||||
1607852717 source:d:\users\think\desktop\mes documents\programmation\arduino\esp8266_swiss_army_board\src\software_test\esp8266tcpstresser\main.cpp
|
||||
<iostream>
|
||||
<string.h>
|
||||
<SFML/Network.hpp>
|
||||
<SFML/System.hpp>
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="826" topLine="9" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
78
src/software_test/ESP8266TCPStresser/main.cpp
Normal file
78
src/software_test/ESP8266TCPStresser/main.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <SFML/Network.hpp>
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace sf;
|
||||
|
||||
void stressConnection(TcpSocket &s, string &ipAddr, uint16_t &port)
|
||||
{
|
||||
uint8_t cpt(0);
|
||||
const char *strings[] = {"Some random data to be sent",
|
||||
"an other frame with random crap",
|
||||
"Still an other thing",
|
||||
"Last but not least me stress you even more"
|
||||
};
|
||||
|
||||
char recvbuffer[4096] = "";
|
||||
size_t recvct(0);
|
||||
|
||||
while(1)
|
||||
{
|
||||
s.receive(recvbuffer, 4095, recvct);
|
||||
cout << "Received : " << recvct << endl;
|
||||
cout << "Data : " << recvbuffer << endl;
|
||||
s.send(strings[cpt], strlen(strings[cpt]));
|
||||
s.disconnect();
|
||||
s.connect(ipAddr, port, sf::milliseconds(100));
|
||||
|
||||
cpt = cpt >= 3 ? 0 : ++cpt;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
string ipAddr;
|
||||
uint16_t port;
|
||||
TcpSocket ts;
|
||||
bool connected(false);
|
||||
|
||||
do
|
||||
{
|
||||
cout << "Welcome to the ESP8266 TCP Stresser" << endl;
|
||||
cout << "Enter the device's IP address (IP V4)" << endl;
|
||||
cin >> ipAddr;
|
||||
cout << "Enter the server's port :" << endl;
|
||||
cin >> port;
|
||||
cout << "Connecting to " << ipAddr << " on port : " << port << endl;
|
||||
|
||||
switch(ts.connect(ipAddr, port, sf::milliseconds(500)))
|
||||
{
|
||||
case Socket::Status::Error :
|
||||
cout << "Unable to connect to device" << endl;
|
||||
break;
|
||||
case Socket::Status::Done :
|
||||
cout << "Done" << endl;
|
||||
connected = true;
|
||||
break;
|
||||
case Socket::Status::NotReady :
|
||||
cout << "NotReady" << endl;
|
||||
break;
|
||||
case Socket::Status::Partial :
|
||||
cout << "Partial" << endl;
|
||||
break;
|
||||
case Socket::Status::Disconnected :
|
||||
cout << "Disconnected" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
if(connected)
|
||||
{
|
||||
stressConnection(ts, ipAddr, port);
|
||||
}
|
||||
|
||||
}while(true);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user