Giter Site home page Giter Site logo

tuddman / socketcluster-clj Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 15 KB

A SocketCluster Client library for Clojure.

Home Page: https://socketcluster.io

License: Eclipse Public License 2.0

Clojure 100.00%
socketcluster socketcluster-client clojure real-time

socketcluster-clj's Introduction

socketcluster-clj

A SocketCluster Client library for Clojure. This client wraps socketcluster-client-java, but where appropriate aims to be more idiomatic and succinct.

Clojars Project

Usage

lein repl

;; define
=> (require '[socketcluster-clj.client :as sc-client])
=> (require '[socketcluster-clj.listeners :as sc-listen])
=> (require '[socketcluster-clj.events :as sc-event])
=> (require '[socketcluster-clj.channels :as sc-ch])
=> (def sc-server-url "ws://localhost:8000/socketcluster/")
=> (def my-socket (sc-client/new-socket sc-server-url)  
or
=> (sc-client/set-url my-socket sc-server-url)

;; set listener(s)
=> (sc-listen/set-listener my-socket)

;; connect
=> (sc-client/connect my-socket)
;; automatically re-connect
=> (sc-client/set-reconnect-strategy my-socket 2000 30)

;; send event(s) to the server
=> (sc-event/emit my-socket {"some" "data"})

;; CHANNELS -

;; subscribe

=> (sc-ch/create-channel my-socket "channel-name")
=> (sc-ch/set-channel-listener my-socket "channel-name" (fn [name data] (print "received on channel => " name "some data => " data)))
=> (sc-ch/subscribe my-socket "channel-name")

;; publish
=> (sc-ch/publish my-socket "channel-name" {"some" "data"})

for more, have a look in src/socketcluster_clj/<ns>.clj to learn what else you can call.

NPE Issue

if you get the following error when trying to connect:

Exception in thread "OkHttp Dispatcher" java.lang.NullPointerException
	at io.github.sac.Socket$1.onFailure(Socket.java:185)
	at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:546)
	at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:206)

you need to (sc-listen/set-listener <socket>) before connecting.

License

Copyright © 2019 tuddman

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

socketcluster-clj's People

Contributors

tuddman avatar

Stargazers

 avatar

Watchers

 avatar  avatar

socketcluster-clj's Issues

Issue with requiring define-ack

 (ns socketcluster-clj.events
   (:require
     [socketcluster-clj.listeners :refer [define-listener define-ack-listener]]))

Misses define-ack
Also socketcluster-clj.channels
I don't know why does it work in your example, but with this error I couldn't import your library.

 (ns socketcluster-clj.events
   (:require
     [socketcluster-clj.listeners :refer [define-listener define-ack-listener define-ack]]))

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.