Home » U++ Library support » U++ MT-multithreading and servers » Socket client out of buffer error and reusing sockets
Socket client out of buffer error and reusing sockets [message #40199] |
Tue, 02 July 2013 11:03 |
|
koldo
Messages: 3358 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
I am a completely newbie in sockets.
When doing a client based in SocketClient demo and running it in a for() loop a WSAENOBUFS is get:
String Request(const String& r)
{
TcpSocket s;
if(!s.Connect(CommandLine().GetCount() ? CommandLine()[0] : "127.0.0.1", 3214)) {
Cout() << "Unable to connect to server!\n";
SetExitCode(1);
return Null;
}
s.Put(r + '\n');
return s.GetLine();
}
CONSOLE_APP_MAIN
{
for (int i = 0; i < 50000; ++i)
Cout() << Request("time") << '\n';
}
However if TcpSocket is reused, the program runs perfectly:
String Request(TcpSocket &s, const String& r) // Added TcpSocket &s
{
if(!s.Connect(CommandLine().GetCount() ? CommandLine()[0] : "127.0.0.1", 3214)) {
Cout() << "Unable to connect to server!\n";
SetExitCode(1);
return Null;
}
s.Put(r + '\n');
return s.GetLine();
}
CONSOLE_APP_MAIN
{
TcpSocket s; // Added TcpSocket s;
for (int i = 0; i < 50000; ++i)
Cout() << Request(s, "time") << '\n'; // Added s
}
Is the conclusion that TcpSocket has to be reused, or TcpSocket is not properly destructed, or maybe both?
Best regards
IƱaki
|
|
|
Goto Forum:
Current Time: Wed May 01 14:49:16 CEST 2024
Total time taken to generate the page: 0.03416 seconds
|