logo
down
shadow

communicating between http handler and websocket handler in Cowboy


communicating between http handler and websocket handler in Cowboy

By : user2955065
Date : November 22 2020, 10:33 AM
Does that help A websocket handler in cowboy is a long lived request process to which you can send websocket or erlang messages.
In your case, there are 2 types of processes:
code :
websocket_init(_, Req, _Opts) ->
  ...
  % l is for local process registration
  % echo is the name of the event you register the process to
  gproc_ps:subscribe(l, echo),
  ...

websocket_info({gproc_ps_event, echo, Echo}, Req, State) ->
  % sending the Echo to the client
  {reply, {text, Echo}, Req, State};
echo(<<"GET">>, Echo, Req) ->
    % sending the echo message to the websockets handlers
    gproc_ps:publish(l, echo, Echo),
    cowboy_req:reply(200, [
        {<<"content-type">>, <<"text/plain; charset=utf-8">>}
    ], Echo, Req);


Share : facebook icon twitter icon
How to handle exceptions in cowboy websocket handler?

How to handle exceptions in cowboy websocket handler?


By : Casey
Date : March 29 2020, 07:55 AM
I wish this help you I am trying to catch invalid json while parsing it with jiffy in cowboy websocket handler. If the json is valid/invalid I want to forward an appropriate message to websocket_info which will reply to the client. Here is my code. , Reply should be returned from websocket_handle:
code :
websocket_handle({text, Msg}, Req, State) ->
    lager:info("Got message ~p", [Msg]),
    try jiffy:decode(Msg) of 
        {[{A, B}]}->
            {reply, {text, jiffy:encode({[{registered,B}]})}, Req, State};
        _ -> 
            {reply, {text, jiffy:encode({[{error,<<"invalid json">>}]})}, Req, State} 
    catch
        _:_ ->
            {reply, {text, jiffy:encode({[{error,<<"invalid json">>}]})}, Req, State};
    end;

websocket_handle(_Data, Req, State) ->
    {ok, Req, State}.

websocket_info(_Info, Req, State) ->
    {ok, Req, State}.
Issue when registering two local process with gproc within cowboy websocket handler

Issue when registering two local process with gproc within cowboy websocket handler


By : Shreyas Yadav
Date : March 29 2020, 07:55 AM
Does that help @Stefan Zobel, you are right,In my onmessage event I have a call to onclose() event.
how can I inject a keep-alive into a websocket handler in akka-http?

how can I inject a keep-alive into a websocket handler in akka-http?


By : DJSY
Date : March 29 2020, 07:55 AM
hope this fix your issue The only way to control how connections are dropped server-side is to change the idle-timeout (see the docs here and here).
You can set
code :
idle-timeout = infinite
Updating state in Cowboy Websocket handler crashes or ignores silently

Updating state in Cowboy Websocket handler crashes or ignores silently


By : Vaishali Nathani
Date : March 29 2020, 07:55 AM
Any of those help The problem is that cowboy's websocket_info/2 handler will only receive messages sent to the websocket process by using the erlang built-in message operator ! (or, equivalently, the erlang:send/{2,3} functions).
So you should do:
Cowboy websocket handler: How to set timeout for first message?

Cowboy websocket handler: How to set timeout for first message?


By : theUNnicked
Date : March 29 2020, 07:55 AM
To fix this issue Just start timer in your websocket_init callback on your own. If user authenticate before timeout, just ignore it, you can achieve this by updating the state when user authenticate himself.
erlang:start_timer documentation:
Related Posts Related Posts :
  • Property 'throw' does not exist on type 'typeof Observable'
  • Unable to deploy SAPUI5 application with 404 error
  • Xcode 10 build fail rm permission denied in /bin/sh/
  • Handling quorum writies fail on Cassandra
  • How to finalize log file just after time is over when using logback SizeAndTimeBasedFNATP?
  • Write custom widget with GTK3
  • How to remove UINavigationBar inner shadow in iOS 7?
  • Wordpress dynamic widget by location?
  • XDocument replace all node value with lower case
  • Invalid tagdir attribute while web-fragment is used
  • Set default font/text size in RTF Control
  • what video formats supported by chromecast device (mp4,flv,m3u8,flv,avi)?
  • sbcl - how to muffle "undefined variable" warning?
  • Get an eventbrite event ID
  • Obtain date without timestamp in DB2
  • Cron job to SFTP files in a directory
  • Draw two head arrows in fabric.js
  • YOLO darknet vs darkflow
  • Parse custom rss tags using Rome API
  • Creating text editor like EDIT on Command Prompt using FreePascal
  • Subplot hides xlabel
  • NServiceBus long running process that timesout
  • Qt4 - How to add a row in a QTableWidget when sorting is enable?
  • Cancel command in Grunt that hasn't been launched
  • Canvas globalCompositeOperation is not working correctly
  • HTML.Kendo().Dropdownlist set default item
  • vagrant up failed, /dev/vboxnetctl: no such file or directory
  • How to use jssor carousel to build client carousal
  • Theory what is meant by validating security concerns for these user groups
  • How to build correct SPARQL Query
  • Connecting to MySQL (on Google Cloud SQL) via JDBC and IPv6?
  • Fetching transaction in several iterations
  • is it possible to use dropbox datastore api as shared datastore?
  • phpExcel 1.8 Named Ranges in Formula
  • Cisco VPN IP address
  • No address associated with hostname using vagrant
  • 2 way data-binding between a polymer component and a model?
  • How can I rename an already published app in the Windows Dev Center?
  • Using Chef 12 , Chef Client unable to connect to chef Server
  • GCM notification not working (GoogleCloudMessaging)
  • Measured GFLOPS is greater then theoretical GFLOPS
  • Progress ABL - strip and add to temp table
  • Errors occuring when make-ing Aircrack-ng on raspberry pi
  • Detecting Handedness from Device Use
  • Query a manual list of data items
  • Similar to pivot - Windows 8.1 Desktop app
  • CKEDITOR And Styles configuration with only toolbar
  • Segmentation fault due to data alignment issue on MIC
  • how to connect a Java app ( java code ) to cloudant?
  • How to download a file/folder from remote (openshift) to local system
  • Where can i find customeditors in JBPM 6
  • Pig get distinct rows with counts
  • In Flex when is yylineno updated?
  • How does a semantic reasoner for protegé is made?
  • how to stop another rows to be select after select a row in uitableview
  • Setup cmd.exe parameter when starting ConEmu
  • WPF how to get the same visual size in different devices
  • How to convert tiff to searchable pdf using alfresco and tesseact?
  • Intel Media SDK: Regarding mfxIMPL Usage
  • How to pass values to SOAP service using web service consumer?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org