<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
You could try <tt><a
href="http://erlang.org/doc/man/timer.html#send_interval-3">timer:send_interval/3</a>:</tt><br>
<br>
<blockquote type="cite"><tt>send_interval(Time, Pid, Message)</tt><br>
Evaluates <tt>Pid</tt> ! <tt>Message</tt> repeatedly after <tt>Time</tt>
milliseconds. (<tt>Pid</tt> can also be an atom of a registered
name.)<br>
</blockquote>
<br>
There's even a <a
href="http://erlang.org/doc/man/timer.html#send_interval-2"><tt>timer:send_interval/2</tt></a>
that assumes <tt>self()</tt> as the <tt>Pid</tt>, which looks like
it might be what you want<tt>:</tt><br>
<br>
<blockquote type="cite"><tt>send_interval(Time, Message)</tt><br>
Same as <tt>send_interval(Time, self(), Message)</tt>.</blockquote>
<br>
One thing to note though is that the <a
href="http://erlang.org/doc/efficiency_guide/commoncaveats.html#id60818">Common
Caveats</a> section says:<br>
<br>
<blockquote type="cite">
<p style="max-width: 42em; color: rgb(26, 26, 26); font-family:
sans-serif; font-size: 16px; font-style: normal;
font-variant-caps: normal; font-weight: normal; letter-spacing:
normal; orphans: auto; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-size-adjust: auto;
-webkit-text-stroke-width: 0px;">Creating timers using<span
class="Apple-converted-space"> </span><span class="bold_code
bc-13" style="font-family: mono, Courier, monospace;
font-weight: bold;"><a
href="http://erlang.org/doc/man/erlang.html#erlang:send_after-3"
style="color: rgb(27, 110, 194); text-decoration: none;">erlang:send_after/3</a></span><span
class="Apple-converted-space"> </span>and<span
class="Apple-converted-space"> </span><span class="bold_code
bc-13" style="font-family: mono, Courier, monospace;
font-weight: bold;"><a
href="http://erlang.org/doc/man/erlang.html#erlang:start_timer-3"
style="color: rgb(27, 110, 194); text-decoration: none;">erlang:start_timer/3</a></span><span
class="Apple-converted-space"> </span>, is much more efficient
than using the timers provided by the<span
class="Apple-converted-space"> </span><span class="bold_code
bc-18" style="font-family: mono, Courier, monospace;
font-weight: bold;"><a
href="http://erlang.org/doc/man/timer.html" style="color:
rgb(27, 110, 194); text-decoration: none;">timer</a></span><span
class="Apple-converted-space"> </span>module in STDLIB. The<span
class="Apple-converted-space"> </span><span class="code"
style="font-family: mono, Courier, monospace; font-weight:
normal; background-color: rgb(243, 243, 243);">timer</span>module
uses a separate process to manage the timers. That process can
easily become overloaded if many processes create and cancel
timers frequently (especially when using the SMP emulator).</p>
</blockquote>
<br>
I'm not sure if that applies to send_interval/{2,3} as well, or
quite how many "many" means there - I guess it's probably "a really
large number", but perhaps somebody could jump in here?<br>
<br>
But if so, and if you expect heavy traffic with an interval like
this on every WS connection, an alternative might be to create a
loop to send the message using <tt>send_after/3</tt> instead of
using the <tt>timer</tt> module. I.e. the process which handles <tt>Msg</tt>
could call <tt>erlang:send_after( Time, self(), Msg )</tt> when
it's done its other work. Working out which process does that would
depend on your app design - it might work to just do it in the
process which handles the message you're sending, or you might need
another process.<br>
<br>
Cheers<br>
i<br>
<br>
<div class="moz-cite-prefix">On 23/09/2017 11:21, Palanikumar
Gopalakrishnan wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAN4mP=pYBj_84Z0RSiPx1_P--Wpf3r9KANrRFUmAuCE+0tpBpA@mail.gmail.com">
<div dir="ltr">
<div>Hi lgor Clark,<br>
</div>
Thanks for the help. yes you are
correct. Its there any way to send message to websocket using <b>timer:apply_interval/4</b>.
I didn't find any examples. <br>
<br>
<br>
<br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On 23 September 2017 at 15:47, Igor
Clark <span dir="ltr"><<a
href="mailto:igor.clark@gmail.com" target="_blank"
moz-do-not-send="true">igor.clark@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"> Hi Palanikumar,<br>
<br>
It looks like you're passing the <tt><a
href="http://erlang.org/doc/man/erlang.html#start_timer-3"
target="_blank" moz-do-not-send="true">erlang:start_timer/3</a></tt>
arguments to <tt><a
href="http://erlang.org/doc/man/timer.html#apply_interval-4"
target="_blank" moz-do-not-send="true">timer:apply_interval/4</a></tt>:<br>
<br>
<tt>erlang:start_timer(Time, Dest, Msg)</tt><br>
<br>
vs<br>
<br>
<tt>apply_interval(Time, Module, Function, Arguments)</tt><br>
<br>
<tt>erlang:start_timer/3</tt> sends <tt>Msg</tt> to <tt>Dest</tt>
after <tt>Time</tt> ms; <tt>timer:apply_interval/4</tt>
calls <tt>Module:Function(Arguments)</tt> every <tt>Time</tt>
ms.<br>
<br>
So the error message is telling you that the function <tt>timer:apply_interval/3</tt>
you're trying to call doesn't exist.<br>
<br>
HTH,<br>
Igor
<div>
<div class="h5"><br>
<br>
<div class="m_6431617450298307261moz-cite-prefix">On
23/09/2017 10:50, Palanikumar Gopalakrishnan wrote:<br>
</div>
</div>
</div>
<blockquote type="cite">
<div>
<div class="h5">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>Hi Guys,<br>
<br>
</div>
I want to send message to
the front-end via websocket in
particular time interval.<br>
</div>
So i use timer module for this purpose.<br>
<b>timer:apply_interval(1000, self(),
<<"How' you doin'?">>),</b></div>
<div><b><br>
</b></div>
<div><b><br>
</b></div>
But it returns the following error<br>
<br>
<b>15:18:20.558 [error] CRASH REPORT Process
<0.570.0> with 0 neighbours crashed
with reason: call to undefined function
timer:apply_interval(6000,
<0.570.0>, <<"How' you
doin'?">>)<br>
15:18:20.558 [error] Ranch listener
my_cowboy_ws_server terminated with
reason: call to undefined function
timer:apply_interval(6000,
<0.570.0>, <<"How' you
doin'?">>)<br>
<br>
<br>
</b></div>
Its there any way to solve this problem. <br>
<br>
</div>
I already tried with <br>
<br>
<b>erlang:start_timer(60000, self(),
<<"How' you doin'?">>)<br>
<br>
</b></div>
Its only send message after particular timer. I
didn't found method in this module to send message
in particular interval.<br>
<br>
<br>
<br>
<div>
<div><br>
<div><br>
<br>
<div>
<div>
<div>
<div><br>
<br>
<div>
<div> <br clear="all">
<div><br>
-- <br>
<div
class="m_6431617450298307261gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div><br>
</div>
<div><b>Warm
Regards,</b></div>
</div>
<div><br>
</div>
<div><span
style="background-color:rgb(255,255,255)"><span
style="font-size:12.8px"><b>Palanikumar Gopalakrishnan </b></span></span><img
alt="✌"
style="font-size:small;margin:0px
0.2ex;vertical-align:middle;height:24px;width:24px"
moz-do-not-send="true"><span
style="background-color:rgb(255,255,255)"><br>
</span></div>
<div><span
style="font-size:12.8px;background-color:rgb(255,255,255)"><b>Developer</b></span><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset
class="m_6431617450298307261mimeAttachmentHeader"></fieldset>
<br>
</div>
</div>
<pre>______________________________<wbr>_________________
erlang-questions mailing list
<a class="m_6431617450298307261moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org" target="_blank" moz-do-not-send="true">erlang-questions@erlang.org</a>
<a class="m_6431617450298307261moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank" moz-do-not-send="true">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a>
</pre>
</blockquote>
<br>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
<div class="gmail_signature" data-smartmail="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div><br>
</div>
<div><b>Warm Regards,</b></div>
</div>
<div><br>
</div>
<div><span
style="background-color:rgb(255,255,255)"><span
style="font-size:12.8px"><b>Palanikumar
Gopalakrishnan </b></span></span><img
src="https://ssl.gstatic.com/mail/emoji/6/48px/emoji_u270c.png"
alt="✌" style="font-size:small;margin:0px
0.2ex;vertical-align:middle;height:24px;width:24px"
moz-do-not-send="true"><span
style="background-color:rgb(255,255,255)"><br>
</span></div>
<div><span
style="font-size:12.8px;background-color:rgb(255,255,255)"><b>Developer</b></span><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>