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++ Core » Problem with websocket connect method
Re: Problem with websocket connect method [message #49012 is a reply to message #48954] Sat, 25 November 2017 13:58 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1093
Registered: August 2007
Senior Contributor
Hello,

I found the problem with connection.
It turned out that

1) IpAddrInfo::Start() is not called (WebSocket.cpp, ln. 94-5.
		if(!ipaddrinfo.Execute(host, port)) {
			Error("Not found");
			return false;
		}
		LLOG("DNS resolved");
		StartConnect();
		while(opcode != READING_FRAME_HEADER) {
			Do0();
			if(IsError())
				return false;
		}
	}
	else {
		opcode = DNS;
		ipaddrinfo.Start(host, port); // <-- Was missing.
	}
	return true;


2) In Do0(), socket is checked for Eof too early (It should be checked after DNS phase, WebSocket, ln. 345-6).
		prev_opcode = opcode;
		if(opcode != DNS)
			if(socket->IsEof() && !(close_sent || close_received))
				Error("Socket has been closed unexpectedly");



3) I also changed addrinfo to ipaddrinfo to avoid any nameclashes and errors (there is already an "addrinfo" structure)
4) A suggestion: We should check for DNS lookup errors too:


void WebSocket::Dns()
{
	if(ipaddrinfo.InProgress())
		return;
        if(!ipaddrinfo.GetResult()) {                         // We should check for lookup errors...
               Error("DNS lookup failed");                   //
               return;
        }
	LLOG("DNS resolved");
	StartConnect();
}


5) Aonther suggestion: I still think that WebSocket::Do() should return a boolean value to indicate progress/finish. I couldn't find a reliable way to check if a non-blocking operation such as Connect() is successful. Currently the only way to break the loop of a non-blocking Connect() call seems to be to check for errors.

From my experience I can say that below code (or other variants of this) would work well on such situations:

    ws.NonBlocking().Connect("127.0.0.1:12321");
    while(ws.Do())
        ;
    if(ws.IsError())
       return;

    // Success, carry on (send/recv)...



You can find the patched files below.

Best regards,
Oblivion




[Updated on: Sat, 25 November 2017 22:47]

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
Read Message
Read Message
Read Message
Read Message
Previous Topic: Bug with FindMatch(const Range& r, const C& match, int from = 0)
Next Topic: Vector<Vector<double>>
Goto Forum:
  


Current Time: Sat Apr 27 16:20:36 CEST 2024

Total time taken to generate the page: 0.02928 seconds