<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="151021" data-post-id="151021">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="deepukjayan" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/deepukjayan/120/16921_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  deepukjayan
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>update: phx_raw doesnt wotk. The Author himself have told that in one of the github issues.</p>
<p>I also tried it, just to make sure. Phoenix tries to handle all the requests and mess up with phx_raw.</p>
<p>Planning to look at custom dispatch…</p><aside class="quote quote-modified" data-post="18" data-topic="10074">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/satom99/48/7286_2.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/plan-old-websockets-in-phoenix-but-without-magic/10074/18" rel="nofollow">Plan old websockets in phoenix but without magic</a> <a class="badge-category__wrapper " href="/c/questions-help/questions/53" rel="nofollow"><span data-category-id="53" style="--category-badge-color: #C14BFB; --category-badge-text-color: #000000; --parent-category-badge-color: #C14BFB;" data-parent-category-id="171" data-drop-close="true" class="badge-category --style-square --has-parent" title="Elixir Questions / Help"><span class="badge-category__name">Questions</span></span></a>
    </div>
  </div>
  <blockquote>
    If I understood you right, this is what we have: 

A client C sends a message to the server S

The server forwards this message to a process P

This process does something with the client’s message  and sends a reply to the client 
Client &gt; Server &gt; Process &gt; Client


What is FancyLib? Why are you defining handle(:data, ...) - there is no such opcode? 

Let me introduce an example. 
defmodule Socket do
  use Phoenix.Socket

  transport :websocket, Phoenix.Transports.Websocket.Raw

  def handle(:…
  </blockquote>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="151021" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/phoenix-socket-how-to-support-wildcard-topic/26883/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-151021" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="151021"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="151054" data-post-id="151054">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a href="https://github.com/meh/elixir-socket" rel="noopener nofollow ugc">elixir-socket</a> is for TCP (or UDP) sockets, not websockets. Which protocol does your device talk ? TCP or websockets ?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="151054" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/phoenix-socket-how-to-support-wildcard-topic/26883/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-151054" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="151054"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="151065" data-post-id="151065">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="idi527" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  idi527
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><img src="https://forum.elixirforum.com/images/emoji/apple/waving_hand.png?v=15" title=":waving_hand:" class="emoji only-emoji" alt=":waving_hand:" loading="lazy" width="20" height="20"></p>
<blockquote>
<p>I have an IOT device that would open a socket connection and start sending data. I really dont have control over how this device send data.</p>
</blockquote>
<p>I used <a href="https://github.com/ninenines/ranch" rel="noopener nofollow ugc">ranch</a> for an iot project in the past. The devices were sending data over tcp, it worked roughly like this:</p>
<p><code>lib/iot_device_server.ex</code></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule IOTDeviceServer do
  @behaviour :ranch_protocol

  @impl true
  def start_link(ref, _socket, transport, opts) do
    pid = :proc_lib.spawn_link(__MODULE__, :init, [ref, transport, opts])
    {:ok, pid}
  end

  @doc false
  def init(ref, transport, _opts) do
    {:ok, socket} = :ranch.handshake(ref)
    __MODULE__.loop(socket, transport)
  end

  @doc false
  def loop(socket, transport) do
    case transport.recv(socket, 0, 5000) do
      {:ok, data} -&gt;
        case handle_in(data) do
          {:reply, reply} -&gt;
            transport.send(socket, reply)

          :noreply -&gt;
            :ok
        end

        loop(socket, transport)

      _ -&gt;
        :ok = transport.close(socket)
    end
  end

  @spec handle_in(binary) :: {:reply, iodata} | :noreply
  defp handle_in(&lt;&lt;...some markers..., _rest::bytes&gt;&gt; = binary_packet) do
    {:ok, packet, _rest} = IOTPacket.decode(binary_packet)
    # :ok = publish(packet) then it was published to a queue
    :noreply
  end
end
</code></pre>
<p><code>lib/application.ex</code></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule IOTDeviceServer.Application do
  @moduledoc false
  use Application

  def start(_type, _args) do
    config = Application.get_all_env(:iot_device_server)

    _children = [
        :ranch.child_spec(IOTDeviceServer, :ranch_tcp, [port: config[:port]], IOTDeviceServer, [])
    ]

    opts = [strategy: :one_for_one, name: IOTDeviceServer.Supervisor]
    Supervisor.start_link(children, opts)
  end
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="151065" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/phoenix-socket-how-to-support-wildcard-topic/26883/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-151065" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="151065"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="151076" data-post-id="151076">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="deepukjayan" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/deepukjayan/120/16921_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  deepukjayan
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="lud" data-post="13" data-topic="26883">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/48/14382_2.png" class="avatar"> lud:</div>
<blockquote>
<p><a href="https://github.com/meh/elixir-socket" rel="noopener nofollow ugc">elixir-socket</a> is for TCP (or UDP) sockets, not websockets.</p>
</blockquote>
</aside>
<p>You are right. My device use ws. What do you think about custom dispatch as a solution?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="151076" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/phoenix-socket-how-to-support-wildcard-topic/26883/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-151076" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="151076"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="151140" data-post-id="151140">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Well if you need to use Phoenix then you have no choice but use custom dispatch.</p>
<p>Now, you could also just use cowboy and not Phoenix at all.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="151140" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/phoenix-socket-how-to-support-wildcard-topic/26883/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-151140" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="151140"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>