Giter Site home page Giter Site logo

ylwebsocket's Introduction

#Unity WebSocket 使用

###1.下载 YLWebSocket.unitypackage

###2.使用Unity导入package。

  • WebSocket.jslib

      路径:Plugins/YLWebSocket/WebSocketJS.jslib
    
      作用:Unity发布WebGL版本会将其加入到js运行库中。
    
  • WebSocket.cs

      作用:作为一个WebSocket连接。
    
  • WebSocketManager.cs

      作用:创建、管理WebSocket的使用,并且负责接收、分发多个WebSocket消息。
    
  • Demo场景

      作用:WebSocket的使用方法示例。
    
  • SimpleMessagePackTool.cs

作用:简单的将 UTF8字符串 和 byte[] 之间相互转换。

###3.使用方法:

  • 创建WebSocket实例
string address = "ws://127.0.0.1:8730/test";

WebSocket scoket = WebSocketManager.instance.GetSocket(address);
  • 注册回调


socket.onConnected += OnConnected;

socket.onClosed += OnClosed;

socket.onReceived += OnReceived;//接收数据类型byte[]

  • 连接

socket.Connect();

  • 发送数据

socket.Send(data);//发送数据类型byte[]

  • 关闭连接

socket.Close();

###4.下载 服务器Demo

  • 提供简单的WebSocket消息收发

  • 使用了开源项目 websocket-sharp

ylwebsocket's People

Watchers

 avatar

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.