Project

General

Profile

Wt as the server API

Added by Georgiy Gluhoedov almost 8 years ago

Hello guys.

How to receive and respond to GET and POST requests?

How to access a list of WebSocket connections and notify them?

Wt can be used as a server API?

Many JavaScript Client -> send Get\Post request -> Wt server send response;

Many JavaScript Client -> WebSocket connect -> Wt server;

Wt server -> notification One or More WebSocket -> JavaScript Client;

Many JavaScript Client -> WebSocket disconnect -> Wt server;

JavaScript Client use XmlHttpRequest and WebSocket.

An example of a client in an attachment.

Br. George.

WebSocket.html (2.05 KB) WebSocket.html Example WebSocket Client

Replies (1)

RE: Wt as the server API - Added by Wim Dumon almost 8 years ago

Georgiy Gluhoedov wrote:

Hello guys.

How to receive and respond to GET and POST requests?

Create a WResource and reimlement handleRequest. The WResource can be bound to a fixed URL (through WServer) or to a session-bound random URL (by using it in a session).

How to access a list of WebSocket connections and notify them?

Wt selects the proper technology to communicate with the browser, be it web sockets or something else. From the server, you can at any moment change an application's widgets and ask the serve to push the modification to the client. This mechanism is described in WApplication::enableUpdates() and similar. Notifications to sessions can be generated by calling WServer::post().

Wt can be used as a server API?

Yes, although Wt offers a nice, structured way of building web applications where you don't need server APIs to build your user interface. The HTTP queries that you mention can be handled by Wt(see my answer above), the websocket requests are not supported at this time.

Best regards,

Wim.

    (1-1/1)