All Projects β†’ leozz37 β†’ hare

leozz37 / hare

Licence: MIT License
πŸ‡ CLI tool for websockets and easy to use Golang package

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to hare

Bizsocket
εΌ‚ζ­₯socketοΌŒε―ΉδΈ€δΊ›δΈšεŠ‘εœΊζ™―εšδΊ†ζ”―ζŒ
Stars: ✭ 469 (+1072.5%)
Mutual labels:  sockets, socketio
Bigq
Messaging platform in C# for TCP and Websockets, with or without SSL
Stars: ✭ 18 (-55%)
Mutual labels:  sockets, messaging
hydra-hpp
Hydra Hot Potato Player (game)
Stars: ✭ 12 (-70%)
Mutual labels:  sockets, messaging
uC-TCP-IP
A compact, reliable, high-performance TCP/IP protocol stack. Features dual IPv4 and IPv6 support, an SSL/TLS socket option, and support for Ethernet, Wi-Fi, and PHY controllers.
Stars: ✭ 66 (+65%)
Mutual labels:  sockets
socketio-shared-webworker
Socket.io client inside a WebWorker thread
Stars: ✭ 85 (+112.5%)
Mutual labels:  socketio
MQL5-JSON-API
Metaquotes MQL5 - JSON - API
Stars: ✭ 183 (+357.5%)
Mutual labels:  sockets
everyone-bot
Telegram bot to get everyone's attention in a group chat. Like @everyone in other messaging applications.
Stars: ✭ 52 (+30%)
Mutual labels:  messaging
messaging-replication
eXist-db JMS based messaging and document replication extension (JMS based)
Stars: ✭ 14 (-65%)
Mutual labels:  messaging
TradingMachine
TradingMachine is a mini-trading system simulation, whose components (market data and order feeds, FIX acceptor and initiator, back-end for filled orders) interact by queues and topics.
Stars: ✭ 26 (-35%)
Mutual labels:  messaging
Tweet-Locator
Tweet locator using ExpressJS, React and Twitter API
Stars: ✭ 109 (+172.5%)
Mutual labels:  socketio
talkjs-examples
TalkJS (https://talkjs.com) examples
Stars: ✭ 60 (+50%)
Mutual labels:  messaging
mmpm
MagicMirror Package Manager
Stars: ✭ 104 (+160%)
Mutual labels:  socketio
amq-examples
This repository contains a set of examples to be used with Red Hat AMQ messaging suite components.
Stars: ✭ 25 (-37.5%)
Mutual labels:  messaging
Socketify
Raw TCP and UDP Sockets API on Desktop Browsers
Stars: ✭ 67 (+67.5%)
Mutual labels:  sockets
pulsar-helm-chart
Official Apache Pulsar Helm Chart
Stars: ✭ 122 (+205%)
Mutual labels:  messaging
bubbly
Full stack chat application created w/ Next.js, Socket.IO, Express, React and TypeScript
Stars: ✭ 24 (-40%)
Mutual labels:  socketio
smallrye-reactive-messaging
SmallRye Reactive Messaging
Stars: ✭ 144 (+260%)
Mutual labels:  messaging
tgcli
Telegram Terminal Application
Stars: ✭ 39 (-2.5%)
Mutual labels:  messaging
gafka
A full ecosystem that is built around kafka powered by golang
Stars: ✭ 96 (+140%)
Mutual labels:  messaging
boltly
Boltly: The complete Socket.io test client!
Stars: ✭ 16 (-60%)
Mutual labels:  socketio

Hare Sockets πŸ‡

Go codecov Mentioned in Awesome Go Go Report Card Codacy Badge Maintainability GoDoc Join the chat at https://gitter.im/hare-sockets/community Release License: MIT

Hare is a user-friendly lib for sockets in Golang and a CLI tool for interaction with sockets. You can send and listen to TCP connections with a few lines of code or commands.

Contents

πŸ–₯️ Installation

Installation guid for the CLI Tool and the Golang Library.

πŸ’» CLI Tool

To install the CLI tool, you can install it through Homebrew:

$ brew tap leozz37/hare

$ brew install hare

Or you can install manually with the Makefile script:

$ make install

πŸ‡ Golang Lib

First, you need Go installed (version 1.12+ is required), then you can install Hare:

$ go get -u "github.com/leozz37/hare"

Import it in your code:

import "github.com/leozz37/hare"

πŸ• Quickstart

Quick start for the CLI Tool and the Golang Library.

πŸ’» CLI Tool

To use the CLI tool, these are the flags:

  -d string
        Data to be sended
  -h string
        Host address to bo operated (default "localhost")
  -l    Listen to a given address
  -p string
        Port address to bo operated         [REQUIRED]
  -s    Send message to a given address

You can run the --help flag:

$ hare --help

To Listen to port 3000 for example, run:

$ hare -l -p 3000

To Send a payload with the message Hello World to port 3000 for example, run:

$ hare -s -p 3000 -d 'Hello World'

cli-example

πŸ‡ Golang Lib

Sample code for sending payloads:

package main

import (
    "github.com/leozz37/hare"
)

func main() {
    hare.Send(3000, "Hello, World")
}

Sample code for listening a port:

package main

import (
    "fmt"

    "github.com/leozz37/hare"
)

func main() {
    r, _ := hare.Listen("3000")

    for {
        if r.HasNewMessages() {
            fmt.Println(r.GetMessage())
        }
    }
}

πŸ“– Documentation

The library consists of two features: listen and send to a given port. You can check the full documentation on Godoc.

Send

Receives a port and a message, both as string and returns an error (if something goes wrong).

func Send(port, message string) error;

Usage example:

func main() {
    err := hare.Send(3000, "Hello, World")
    if err != nil {
        panic(err)
    }
}

Listen

Receives a port as string and returns a Listener struct and an error (if something goes wrong).

func Listen(port string) (*Listener, error);

Usage example:

func main() {
    r, _ := hare.Listen("3000")
    l, _ := hare.listen("3001")

    for {
        if r.HasNewMessages() {
            fmt.Println(r.GetMessage())
        } else if l.HasNewMessages() {
            fmt.Println(l.GetMessage())
        }
    }

Listener

The Listener struct returned by Listen() function has the following fields:

type Listener struct {
    SocketListener net.Listener
    HasNewMessages func() bool
    GetMessage     func() string
    Stop           func()
}

SocketListener is the socket connection.

listener.SocketListener, _ = net.Listen("tcp", "localhost:" + port)

HasNewMessages() function returns a bool being true with there's a new message:

func main() {
    r, _ := hare.Listen("3000")

    if r.HasNewMessages() {
        fmt.Println("There's a new message!")
    }
}

GetMessage() function returns a string with the last message received on the socket:

func main() {
    r, _ := hare.Listen("3000")

    if r.HasNewMessages() {
        fmt.Println(r.GetMessage())
    }
}

Stop() function closes the listener connection:

func main() {
    r, _ := hare.Listen("3000")
    hare.Send("3000", "Hey beauty")

    r.Stop()

    err := Send("3000", "This should fails")
    if err != nil {
        panic(err)
    }
}

πŸ“™ Examples

You can check the example for code usages, like send and listen samples.

Since Hare only listens and send messages, here's a complete example:

package main

import (
    "fmt"
    "time"

    "github.com/leozz37/hare"
)

func listenSockets(port string) {
    r, _ := hare.Listen(port)

    for {
        if r.HasNewMessages() {
            fmt.Println(r.GetMessage())
        }
    }
}

func main() {
    go listenSockets("3000")
    go listenSockets("3001")

    for {
        hare.Send("3000", "Hello port 3000")
        hare.Send("3001", "Hello port 3001")
        time.Sleep(time.Second)
    }
}

πŸ§ͺ Testing

To run the test suite, you can run with:

$ go test

If you want a more detailed report with coverage and an coverage.out file, do the following:

$ go test -v -covermode=count -coverprofile=coverage.out

🀝 Contributing

A full guideline about contributing to Hare can be found in the CONTRIBUTING.md file.

βš–οΈ License

Hare is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].