Giter Site home page Giter Site logo

mendrugory / enchufeweb Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 9 KB

Enchufeweb is a websocket client library written in Elixir

Home Page: https://hex.pm/packages/enchufeweb

License: MIT License

Elixir 100.00%
websocket websocket-client websocket-library elixir-lang

enchufeweb's Introduction

Enchufeweb

hex.pm hexdocs.pm Build Status

Enchufeweb is a websocket client library written in Elixir and based on the Erlang library websocket_client.

Installation

Add enchufeweb to your list of dependencies in mix.exs:

def deps do
[{:enchufeweb, "~> 0.2.1"}]
end

How to use it

  • Implementation of the Websocket Client
defmodule Client do
use Enchufeweb
def handle_message(data, state) do 
IO.inspect data
{:ok, state}
end
def handle_connection(_, state), do: {:ok, state}
def handle_disconnection(_, state), do: {:close, "end", state}
end
  • Connect the client and send a message
iex> {:ok, client} = Client.start_link([url: "ws://localhost:8888/websocket", ws_opts: %{conn_mode: :once}]) 
iex> Client.ws_send(client, "Hola")
  • Send a ping
iex> Client.ws_send(client, :ping)
  • Close the connection
iex> Client.ws_send(client, :close)
  • Client which will send a message just after the connection
defmodule Client do
use Enchufeweb
def handle_message(data, state) do 
IO.inspect data
{:ok, state}
end
def handle_connection(_, state), do: {:reply, "Initial message", state}
def handle_disconnection(_, state), do: {:close, "end", state}
end

Test

Run the tests.

mix test 

enchufeweb's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

camonz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.