Commit 23c18175 authored by Pavel Vainerman's avatar Pavel Vainerman

Добавил код для внутреннего тестирования обмена через UTCPSocket

parent f98f5e49
......@@ -442,6 +442,7 @@ AC_CONFIG_FILES([Makefile
tests/MQPerfTest/Makefile
tests/PocoTest/Makefile
tests/UHttpTest/Makefile
tests/TCPSocketTest/Makefile
docs/Makefile
docs/UniSetDox.cfg
docs/UniSetDoxDevel.cfg
......
SUBDIRS=MQPerfTest PocoTest UHttpTest
SUBDIRS=MQPerfTest PocoTest UHttpTest TCPSocketTest
if HAVE_TESTS
############################################################################
# This file is part of the UniSet library #
......
noinst_PROGRAMS = sock-client sock-server
sock_client_LDADD = $(top_builddir)/lib/libUniSet2.la $(SIGC_LIBS) $(POCO_LIBS)
sock_client_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include $(SIGC_CFLAGS) $(POCO_CFLAGS)
sock_client_SOURCES = sock-client.cc
sock_server_LDADD = $(top_builddir)/lib/libUniSet2.la $(SIGC_LIBS) $(POCO_LIBS)
sock_server_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include $(SIGC_CFLAGS) $(POCO_CFLAGS)
sock_server_SOURCES = sock-server.cc
#!/bin/sh
function usage()
{
echo "Usage: bash_server.sh IP PORT"
exit 0
}
[ -z "$1" ] && usage
[ -z "$2" ] && usage
nc $1 $2 -lkvD
\ No newline at end of file
#include "UTCPStream.h"
#include "UniSetTypes.h"
#include <iostream>
// --------------------------------------------------------------------------
using namespace std;
// --------------------------------------------------------------------------
int main(int argc, const char** argv)
{
try
{
std::string host = "localhost";
if( argc >1 )
host = std::string(argv[1]);
uniset::UTCPStream tcp;
while(true)
{
{
tcp.create(host,2048);
std::string buf = "1234567890.10.11.12.13.14.15.16.17.18.29.20.21ksdjcb sdjcb sldfjvbds fljvhbds jfvhbdsbvjksdbfvjdssvksdbvjsdbvjsbfjskdfbvjsdfbvjdfbvFINISH\n";
size_t nbytes = tcp.sendBytes(buf.data(),buf.size());
cout << "real bytes: " << buf.size()<< " send: " << nbytes << " bytes" << endl;
tcp.disconnect();
}
msleep(5000);
}
return 0;
}
catch( const std::exception& e )
{
cerr << "(sock-client): " << e.what() << endl;
}
catch(...)
{
cerr << "(sock-client): catch(...)" << endl;
}
return 1;
}
#include "UTCPSocket.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/SocketStream.h"
#include <iostream>
// --------------------------------------------------------------------------
using namespace std;
using namespace Poco;
// --------------------------------------------------------------------------
int main(int argc, const char** argv)
{
try
{
uniset::UTCPSocket sock("localhost",2048);
while(true)
{
Net::StreamSocket ss = sock.acceptConnection();
Poco::FIFOBuffer buf(1000);
if( ss.poll(uniset::UniSetTimer::millisecToPoco(5000), Poco::Net::Socket::SELECT_READ) )
{
int r = ss.receiveBytes(buf);
cout << "recv(" << r << "): used=" << buf.used() << " [ ";
for( size_t i=0; i<r; i++)
cout << (int)buf[i];
// std::unique_ptr<char[]> data(new char[buf.used()]);
// buf.read(data.get(), r);
// cout << std::string(data.get(), r) << endl;
cout << " ]" << endl;
}
}
return 0;
}
catch( const std::exception& e )
{
cerr << "(sock-server): " << e.what() << endl;
}
catch(...)
{
cerr << "(sock-server): catch(...)" << endl;
}
return 1;
}
......@@ -453,6 +453,9 @@ src/Various/ujson.cc
src/Makefile.am
tests/UniXmlTest/Makefile.am
tests/UniXmlTest/XmlTest.cc
tests/TCPSocketTest/sock-client.cc
tests/TCPSocketTest/sock-server.cc
tests/TCPSocketTest/Makefile.am
tests/int_unsigned.cc
tests/Makefile.am
tests/test.xml
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment