Overview
Features
Download
Documentation
Community
Add-Ons & Services

Connect Websocket with Poco libraries

Please post support and help requests here.

Connect Websocket with Poco libraries

Postby lion87 » 30 Aug 2013, 14:06

I am trying to connect to the Echo Test Websocket (http://www.websocket.org/echo.html) using the Poco C++ libraries. In order to do so,
here is my code which should set up the Websocket:
Code: Select all
HTTPClientSession cs("echo.websocket.org");
HTTPRequest request(HTTPRequest::HTTP_GET, "/ws");
HTTPResponse response;

WebSocket* m_psock = new WebSocket(cs, request, response);
m_psock->close(); //close immidiately

However it does not work: I am getting an error message like this:

Code: Select all
Poco::Exception: WebSocket Exception: Cannot upgrade to WebSocket connection: Not Found


Can anybody help?

kind regards
lion87
 
Posts: 3
Joined: 01 Aug 2013, 15:33

Re: Connect Websocket with Poco libraries

Postby richard » 01 Dec 2013, 10:43

The request version must be 1.1.

See: http://stackoverflow.com/questions/2018 ... ket-server
richard
 
Posts: 2
Joined: 01 Dec 2013, 00:56

Re: Connect Websocket with Poco libraries

Postby treeze » 26 Aug 2014, 08:03

Hello !

Currently I'm facing similar issue :(

After:

Code: Select all
HTTPClientSession cs( "echo.websocket.org" );

HTTPRequest request( HTTPRequest::HTTP_GET, "/wss", HTTPRequest::HTTP_1_1 );

HTTPResponse response;

WebSocket* ws = new WebSocket( cs, request, response );

cs.sendRequest( request );


I'm getting:

Code: Select all
case POCO_ECONNREFUSED:
   throw ConnectionRefusedException(arg, code);


Someone willing to help ? :)
treeze
 
Posts: 2
Joined: 26 Aug 2014, 07:59

Re: Connect Websocket with Poco libraries

Postby gregee123 » 27 Aug 2014, 01:04

Guys, where did you get the "/ws" or "/wss" paths from? WebSocket.org certainly doesn't seem to be using them.

Apart from that @trezee, if you want a secure connection you need HTTPSClientSession not HTTPClientSession but try plain HTTP first.
currently using: 1.5.4
gregee123
 
Posts: 55
Joined: 29 Mar 2013, 12:11

Re: Connect Websocket with Poco libraries

Postby waynix » 29 Aug 2014, 10:15

The example does not use the "Upgrade" command to identify the websocket connection it uses the URI to decide if a websocket was called.
Code: Select all
if (request.getURI() == "/ws")


Change the variable from
Code: Select all
var wsUri = "ws://echo.websocket.org/";
to
Code: Select all
var wsUri = "ws://echo.websocket.org/ws";
and the offline example at the bottom of websocket.org will work.
Currently using develop
waynix
 
Posts: 3
Joined: 27 Aug 2014, 11:47

Re: Connect Websocket with Poco libraries

Postby gregee123 » 29 Aug 2014, 10:47

But they use poco to write the client side and to connect to websocket.org. They don't use the JS from that website to connect to POCO websocket example.
currently using: 1.5.4
gregee123
 
Posts: 55
Joined: 29 Mar 2013, 12:11


Return to Support

Who is online

Users browsing this forum: guenter and 4 guests