Coder Social home page Coder Social logo

gniazdo's Introduction

Gniazdo

Gniazdo is a WebSocket client for Clojure. Its main purpose is testing WebSockets services without a browser. It uses Jetty's implementation of the WebSocket protocol. It supports both ws:// and wss:// schemas.

Build Status

Usage

Add the following artifact to :dependencies in your project.clj:

Latest version

Here's a minimal usage example:

(require [gniazdo.core :as ws])
(def socket
  (ws/connect
    "ws://example.org:1234/socket"
    :on-receive #(prn 'received %)))
(ws/send-msg socket "hello")
(ws/close socket)

(gniazdo.core/connect uri & options)

gniazdo.core/connect opens a WebSocket connection using a given uri. The following options/callbacks are available:

  • :on-connect – a unary function called after the connection has been established. The handler is a Session instance.
  • :on-receive – a unary function called when a message is received. The argument is a received String.
  • :on-binary – a ternary function called when a message is received. Arguments are the raw payload byte array, and two integers: the offset in the array where the data starts and the length of the payload.
  • :on-error – a unary function called on in case of errors. The argument is a Throwable describing the error.
  • :on-close – a binary function called when the connection is closed. Arguments are an int status code and a String description of reason.
  • :headers – a map of string keys and either string or string seq values to be used as headers for the initial websocket connection request.
  • :client – an optional WebSocketClient instance to be used for connection establishment; by default, a new one is created internally on each call.
  • :subprotocols – an optional sequence of Strings specifying the subprotocols to announce.

gniazdo.core/connect returns an opaque representation of the connection.

See also WebSocketListener.

(gniazdo.core/send-msg [conn message])

gniazdo.core/send-msg sends a given message using a connection established with gniazdo.core/connect. The message should be a String, byte[] or java.nio.ByteBuffer.

(gniazdo.core/close [conn])

gniazdo.core/close closes a connection established with gniazdo.core/connect.

(gniazdo.core/client [] [uri])

gniazdo.core/client creates an instance of WebSocketClient, optionally based on the given URI. If secure WebSocket connections are desired, an SSL-capable instance will be created.

Note that the resulting client has to be started ((.start client)) before it can be used with gniazdo.core/connect.

License

Copyright 2013 stylefruits GmbH

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.

gniazdo's People

Contributors

casidiablo avatar jstepien avatar

Watchers

 avatar  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.