Skip to content

Latest commit

 

History

History
65 lines (41 loc) · 1.6 KB

README_EN.md

File metadata and controls

65 lines (41 loc) · 1.6 KB

(中文版)

Online Demo

Quick Start

Requirements

  • Unity 2018.3 or higher.

Installation

  • Install via Package Manager (Recommended)

    Open Window/Package Manager in the Unity menu bar, click the + icon at the top left, select Add package from git URL..., enter https://github.com/psygames/UnityWebSocket.git#upm and confirm.

  • Install via Unity Package

    Download the latest version of UnityWebSocket.unitypackage from the Releases page, then import the package into your project.

Usage

  • Easy to use

    // the namespace
    using UnityWebSocket;
    
    // create instance
    string address = "ws://echo.websocket.org";
    WebSocket socket = new WebSocket(address);
    
    // register callback
    socket.OnOpen += OnOpen;
    socket.OnClose += OnClose;
    socket.OnMessage += OnMessage;
    socket.OnError += OnError;
    
    // connect
    socket.ConnectAsync();
    
    // send string data 
    socket.SendAsync(str);
    // or send byte[] data (suggested)
    socket.SendAsync(bytes); 
    
    // close connection
    socket.CloseAsync();
  • For more usage, refer to the UnityWebSocketDemo.cs example code in the project.

  • Menus

    • Tools -> UnityWebSocket, version update check, bug report, etc.
  • Unity Define Symbols(Optional):

    • UNITY_WEB_SOCKET_LOG Open internal log info.