Coder Social home page Coder Social logo

bytesocks's Introduction

bytesocks

bytesocks is a fast & lightweight WebSocket server.

It allows clients to create "channels", connect using the WebSocket protocol and exchange messages with other clients in the same channel.

In many ways bytesocks is the "socket" sibling of bytebin. bytebin accepts http get and post requests which allows clients to exchange data asynchronously (client A posts, then client B reads later), whereas bytesocks uses sockets to send messages synchronously (in real time and bidirectionally, client A sends and client B receives).

Running bytesocks

The easiest way to spin up a bytesocks instance is using Docker. Images are automatically created and published to GitHub for each commit/release.

Assuming you're in the bytesocks directory, just run:

$ docker compose up

You should then (hopefully!) be able to access the application at http://localhost:3000/.

It's that easy!

API Usage

Create a channel

To create a channel, send an HTTP GET request to /create.

A unique key that identifies the newly created channel will be returned. You can find it:

  • In the response Location header.
  • In the response body, encoded as JSON - {"key": "aabbcc"}.

Join a channel

Send an HTTP GET request to /{key} with the headers:

Connection: Upgrade
Upgrade: websocket

At this stage it's probably easier to find an HTTP client library that supports web sockets instead of reimplementing the protocol yourself!

License

MIT, have fun!

bytesocks's People

Contributors

lucko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bytesocks's Issues

LuckPerms plugin cannot establish socket connection

Hi, I'm trying to make a selhosted luckpermsWeb.
I raised a bytebin docker container and it works great
The web editor is already working, but not in dynamic mode.

Server running in docker
https://github.com/itzg/docker-minecraft-server

Server type - Spigot
Server version - 1.19.2

I am trying to raise websockets in docker

docker-compose.yml:

version: "3.8"
services:
  bytesocks:
    image: ghcr.io/lucko/bytesocks
    ports:
      - 3001:8080
    environment:
      # You can configure bytesocks using
      # environment variables.
      BYTESOCKS_MISC_KEYLENGTH: 15
    extra_hosts:
      - "host.docker.internal:host-gateway"

But I am getting these errors

docker logs mc-server:

[01:24:19] [Server thread/INFO]: sav_miner issued server command: /lp editor
[01:24:19] [OkHttp https://host.docker.internal:3000/.../WARN]: [LuckPerms] Exception occurred in web socket
java.net.ProtocolException: Expected HTTP 101 response but was '404 Not Found'
	at me.lucko.luckperms.lib.okhttp3.internal.ws.RealWebSocket.checkUpgradeSuccess(RealWebSocket.java:224) ~[?:?]
	at me.lucko.luckperms.lib.okhttp3.internal.ws.RealWebSocket$1.onResponse(RealWebSocket.java:195) ~[?:?]
	at me.lucko.luckperms.lib.okhttp3.RealCall$AsyncCall.execute(RealCall.java:174) ~[?:?]
	at me.lucko.luckperms.lib.okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
	at java.lang.Thread.run(Unknown Source) ~[?:?]
[01:24:24] [luckperms-command-executor/WARN]: [LuckPerms] Unable to establish socket connection
java.lang.RuntimeException: Timed out waiting to socket to connect
	at me.lucko.luckperms.common.webeditor.socket.WebEditorSocket.waitForConnect(WebEditorSocket.java:103) ~[?:?]
	at me.lucko.luckperms.common.webeditor.WebEditorSession.createSocket(WebEditorSession.java:96) ~[?:?]
	at me.lucko.luckperms.common.webeditor.WebEditorSession.open(WebEditorSession.java:87) ~[?:?]
	at me.lucko.luckperms.common.webeditor.WebEditorSession.createAndOpen(WebEditorSession.java:62) ~[?:?]
	at me.lucko.luckperms.common.commands.misc.EditorCommand.execute(EditorCommand.java:111) ~[?:?]
	at me.lucko.luckperms.common.command.abstraction.SingleCommand.execute(SingleCommand.java:56) ~[?:?]
	at me.lucko.luckperms.common.command.abstraction.SingleCommand.execute(SingleCommand.java:48) ~[?:?]
	at me.lucko.luckperms.common.command.CommandManager.execute(CommandManager.java:265) ~[?:?]
	at me.lucko.luckperms.common.command.CommandManager.lambda$executeCommand$1(CommandManager.java:169) ~[?:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.run(Unknown Source) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
	at java.lang.Thread.run(Unknown Source) ~[?:?]
Caused by: java.util.concurrent.TimeoutException
	at java.util.concurrent.CompletableFuture.timedGet(Unknown Source) ~[?:?]
	at java.util.concurrent.CompletableFuture.get(Unknown Source) ~[?:?]
	at me.lucko.luckperms.common.webeditor.socket.WebEditorSocket.waitForConnect(WebEditorSocket.java:101) ~[?:?]
	... 12 

This creates a channel

  [02:18:38 INFO]: [CREATE]
    channel id = JIVnBpcLwQ1n4pL
    user agent = curl/7.87.0
    ip = 192.168.192.1

I also have nginx configured. Because the plugin was throwing the sun.security.provider.certpath.SunCertPathBuilderException error. Therefore, I had to raise nginx to provide an https connection.

nginx.conf:

server {
         listen 443 ssl;

         ssl_certificate /certs/bytesocks/server.crt;
         ssl_certificate_key /certs/bytesocks/server.key;

         error_page 497 =301 https://$host:3000$request_uri;

         location / {
             client_max_body_size 30M;
             client_body_timeout 60s;

             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header X-Forwarded-Proto $scheme;
             proxy_redirect http:// https://;

             proxy_pass http://host.docker.internal:3001/;
         }
     }

I don't think that's the problem either. Because:

  1. curl localhost:3001 (direct port) and curl localhost:3000 return just a "/"
  2. curl -IL localhost:3001 (direct port) and curl https://localhost:3000 (https because nginx redirect) output is 404
  3. For both i can create channel curl localhost:*/create
  4. Can connect to socket websocat ws://host.docker.internal:*/<id>

Unfortunately, I have not found documentation for bytesocks anywhere.
On the LuckPerms wiki under "Self hosting the web interfaces" also no mention of bytesocks

Is the target Java version for this project Java 8?

I see in the pom that the target Java version is Java 8.

javap -v BytesocksClientImpl.class shows major version: 55 which corresponds to Java 11.

This is causing the class to fail to load on my server and breaking Spark.

Is this project somehow being compiled with JDK 11?

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.