Home » U++ Library support » U++ MT-multithreading and servers » [SOLVED] A problem with TcpSocket::GetLine()
[SOLVED] A problem with TcpSocket::GetLine() [message #41354] |
Tue, 03 December 2013 16:33 |
Oblivion
Messages: 1094 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
I am trying to use the TcpSocket::GetLine() method, and I have encountered a problem.
When I try to connect to a server and read the input (here, a single line, server "hello" message, ending with \n") with the GetLine() method, below code always encounter a timeount error and returns immediately. But when I use, say, Get(512), it works as expected. Why is GetLine() method not working here, and what am I doing wrong, any ideas?
Thanks in advance.
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
TcpSocket socket;
if(!socket.Connect("pop.gmail.com", 995)) {
Cout() << "Socket error encountered: " << socket.GetErrorDesc() << "\r\n";
Exit(1);
}
if(!socket.StartSSL()) {
if(socket.IsOpen()) socket.Close();
Cout() << "Couldn't start SSL session.\r\n";
Exit(1);
}
// 5 secs.
socket.Timeout(5000);
// Get() method is working as expected
// String server_hello = socket.Get(512);
// GetLine() method always fails with a timeout error.
// No matter if timeout value witle the GlobalTimeout() or the Timeout() method is set.
String server_hello = socket.GetLine();
if(IsNull(server_hello))
Cout() << "An error occured: " << socket.GetErrorDesc() << "\r\n";
else
Cout() << server_hello << "\r\n";
if(socket.IsOpen())
socket.Close();
}
Regards.
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Tue, 17 December 2013 15:38] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Wed Jun 05 06:12:53 CEST 2024
Total time taken to generate the page: 0.02111 seconds
|