Git Product home page Git Product logo

wsecli's Introduction

Analytics Build Status

wsecli

A WebSocket client written in Erlang

Features

  • Built using wsock
  • Supports both "ws://" and "wss://" schemes.
  • Offers callbacks for events that might occur during the client life: on_open, on_close, on_message and on_error.

Supported protocol versions

Only the protocol specificied at RFC6455 (version 13) is supported. Notice that currently, neither subprotocols nor extensions are supported.

Build ###

Add this repo as a dependency to your rebar.config file

{wsecli, ".*", {git, "https://github.com/esl/wsecli", {tag, master}}}

and then

./rebar compile

Usage ###

I will demostrate its usage with the echo service at www.websocket.org.

  1. Start it, using the function wsecli:start/4

    1>wsecli:start("echo.websocket.org", 80, "/", []).

    or the function wsecli:start/2

    2>wsecli:start("ws://echo.websocket.org/", []).

    The valid options for the client are:

    • {registered, true | false | atom()}. When true the client will be registered using the default name wsecli, when false it will not be registered and any other atom will be used as the name to register with. By default it will not be registered.
  2. Add a callback for received messages,

    3>wsecli:on_message(fun(text, Message)-> io:format("Echoed message: ~s ~n", [Message]) end).
  3. Send a message that will be echoed,

    4> wsecli:send("Hello").
    ok
    Echoed message: Hello
  4. And finally to stop it

    5>wsecli:stop().

Callbacks

Callbacks for the events: on_open, on_error, on_message and on_close can be added. Check the code or the documentation for details.

Tests

Unit tests

Unit test where done with the library espec by lucaspiller.

To run them

rake spec

or, in case you don't have rake installed,

./rebar compile && ERL_LIBS='deps/' ./espec test/spec/

TODO

  • Support streaming of data.
  • Support subprotocol and extensions.

###Author Farruco Sanjurjo. You can contact me at:

License

Copyright [2013] [Farruco Sanjurjo Arcay]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contribute

If you find or think that something isn't working properly, just open an issue.

Pull requests and patches (with tests) are welcome.

wsecli's People

Contributors

madtrick avatar erszcz avatar mpmiszczyk avatar fenek avatar michalwski avatar bartekgorny avatar dcorbacho avatar arcusfelis avatar philwitty avatar

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.