Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous message
Oblivion is currently offline  Oblivion
Messages: 1091
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.


[Updated on: Tue, 17 December 2013 15:38]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: COM servers
Next Topic: GuiMT compilation error on ubuntu12.04
Goto Forum:
  


Current Time: Thu Mar 28 13:45:27 CET 2024

Total time taken to generate the page: 0.00889 seconds