Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Unity Web Sockets provides a wrapper for using Web Sockets, an advanced technology that allows real-time interactive communication between the client browser and a server. It uses a completely different protocol that allows bidirectional data flow, making it unique against HTTP.

License

Notifications You must be signed in to change notification settings

jeffreylanters/unity-web-sockets

Repository files navigation

readme splash

license openupm build deployment stars awesome size sponsors donate

Unity Web Sockets provides a wrapper for using Web Sockets, an advanced technology that allows real-time interactive communication between the client browser and a server. It uses a completely different protocol that allows bidirectional data flow, making it unique against HTTP.

Installation · Documentation · License

Made with ♥ by Jeffrey Lanters

Installation

Using the Unity Package Manager

Install the latest stable release using the Unity Package Manager by adding the following line to your manifest.json file located within your project's Packages directory, or by adding the Git URL to the Package Manager Window inside of Unity.

"nl.elraccoone.web-sockets": "git+https://github.com/jeffreylanters/unity-web-sockets"

Using OpenUPM

The module is availble on the OpenUPM package registry, you can install the latest stable release using the OpenUPM Package manager's Command Line Tool using the following command.

openupm add nl.elraccoone.web-sockets

Documentation

Example Usage

using UnityEngine;
using ElRaccoone.WebSockets;

public class SocketService : MonoBehaviour {

  private WSConnection wsConnection = new WSConnection ("wss://localhost:3000");

  private void Awake () {
    this.wsConnection.OnConnected (() => {
      Debug.Log ("WS Connected!");
    });

    this.wsConnection.OnDisconnected (() => {
      Debug.Log ("WS Disconnected!");
    });

    this.wsConnection.OnError (error => {
      Debug.Log ("WS Error " + error);
    });

    this.wsConnection.OnMessage (message => {
      Debug.Log ("Received message " + message);
    });

    this.wsConnection.Connect ();

    // Queue sending messages, these will always be send in this order.
    this.wsConnection.SendMessage("Hello,");
    this.wsConnection.SendMessage("World!");
  }

  private void OnDestroy () {
    // A provided editor script closes all connections automatically when you
    // exit play mode. Use this method to close the connection manually.
    this.wsConnection.Disconnect ();
  }
}

About

Unity Web Sockets provides a wrapper for using Web Sockets, an advanced technology that allows real-time interactive communication between the client browser and a server. It uses a completely different protocol that allows bidirectional data flow, making it unique against HTTP.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Languages