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 #49015 is a reply to message #49012] Sun, 26 November 2017 13:03 Go to previous messageGo to previous message
shutalker is currently offline  shutalker
Messages: 15
Registered: November 2017
Location: Moscow
Promising Member
Hello!
Thank you very much!
I hope your patch will appear in release sources soon.

Quote:

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)...



As far as I can see, it's the same to:
    ws.Connect("127.0.0.1:12321");

    if(ws.IsError())
       return;

    ws.NonBlocking();
    // Success, carry on (send/recv)...


I also have a suggestion: it would be great to check whether connect is successful via special method (e.g. IsConnected()) that returns true after the client has received websocket header from server in "handshake" stage. Roughly like this:
void WebSocket::ResponseHeader()
{
	if(ReadHttpHeader()) {
		LLOG(data);
		if(ToLower(data).Find("upgrade: websocket") < 0) {
			Error("Invalid server response HTTP header");
			return;
		}
		LLOG("HTTP response header received");
		opcode = READING_FRAME_HEADER;

                isConnected = true;        // <-- "handshake" successful

		data.Clear();
	}
}


bool WebSocket::IsConnected()
{
    return ( !socket->IsEof() && isConnected );
}
 
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 22:52:42 CEST 2024

Total time taken to generate the page: 2.02320 seconds