fenetre is essentially a socket router. You set up route listeners with one or two callbacks. The first callback will define how the socket receives data. The second will define how the server receives data from the socket.
;fenetre;fenetre;fenetre;fenetre
Request object
Each call back inside of a fenetre.at
will have a request
parameter. The request parameter will have a params
property and a query
property. In the case of a write callback there will also be a data
property that represents whatever the socket send to your server.
Example
/*If the following route received a socket at this address "ws://localhost:8335/socket/the/123?my=data"And the same socket sent the string "test"Then all of the contained comparative expression would be true */fenetre;
Sending data
In each callback function whether sending data or receiving data the context (this
) will always be the server-side socket that is sending or receiving the data. This is most important for sending back data as the send
method is on this
.
fenetre;
Route priority
Sometimes some routes will be very similar such as "/test/example"
and "/test/:id"
. In this case a request to "ws://localhost:8335/test/example"
would prefer "/test/example"
over "/test/:id"
. Hard coded values are always matched over parameters.
More route complications are explained as such
"/ptest/test/test" > "/ptest/:id/test" > "/ptest/:id/:sid" > "/:id/:sid/:ssid"
More hard matches are preferred over parameters, but really I'd hope you never need to know any of this.