U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Core » Problem with websocket connect method
Re: Problem with websocket connect method [message #49007 is a reply to message #49006] Fri, 24 November 2017 21:02 Go to previous messageGo to previous message
shutalker is currently offline  shutalker
Messages: 15
Registered: November 2017
Location: Moscow
Promising Member
Hello Oblivion!
Thank you for the reply!

Here's main part of simple nonblocking WebSocket client:
...
WebSocket ws;
    
ws.NonBlocking().Connect("ws://127.0.0.1:8888");

while( true )
{
    ws.Do();
		
    if( ws.IsClosed() || ws.IsError() )
    {
	LOG( ws.GetErrorDesc() );
	break;	
    }
		
    SocketWaitEvent event;
		
    ws.AddTo( event );		
    event.Wait( 1000 );
		
    if( event[0] & WAIT_READ )
    {
        String response = ws.Receive();
			
	    if( !response.IsEmpty() )
		LOG( response );
    }
    else if( event[0] & WAIT_WRITE )
	ws.SendText( AsString( Random() ) );
}
...

It's a training code)

When I'm trying to run it I get error message: "Socket has been closed unexpectedly".
Is it the correct way I manage my websocket?
Could you explain how should I exactly create connection in this case in nonblocking mode?
 
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 Jun 20 04:25:02 GMT+2 2026

Total time taken to generate the page: 0.00743 seconds