GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Unity3dAzure/UnityWebSocket: Web Socket client for Unity

BranchesTags
Open more actions menu

Latest commit

 

History

9 Commits
9 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
Events
Events
 
 
Handlers
Handlers
 
 
Receivers
Receivers
 
 
UnityInspector
UnityInspector
 
 
WebSocket
WebSocket
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
UnityWebSocket.cs
UnityWebSocket.cs
 
 
UnityWebSocketScript.cs
UnityWebSocketScript.cs
 
 
omnisharp.json
omnisharp.json
 
 

Repository files navigation

Web Sockets for Unity

For Unity developers looking to use Web Sockets in their Unity game / app.

External dependencies

First download the required dependencies and extract the contents into your Unity project "Assets" folder.

  • WebSocket-Sharp* forked for supporting custom headers

Features

  • IWebSocket interface for targeting the various platforms Unity supports.
    • WebSocketMono utilizes WebSocket-Sharp* and should work on all mono platforms including the Unity Editor on Mac and PC.
    • WebSocketUWP utilizes MessageWebSocket for Windows 10 (UWP) apps.

Interface methods

API Description
ConfigureWebSocket(url) Configures web socket with url and optional headers
ConnectAsync() Connect to web socket
CloseAsync() Close web socket connection
SendAsync(data) Send binary byte[] or UTF-8 text string with optional callback
IsOpen() Check if web socket status is open
Url() Return the URL being used by the web socket

Interface event delegates

OnError(object sender, WebSocketErrorEventArgs e);
OnOpen(object sender, EventArgs e);
OnMessage(object sender, WebSocketMessageEventArgs e);
OnClose(object sender, WebSocketCloseEventArgs e);

Usage

UnityWebSocketDemo project repo contains sample scenes showing how to hook all this up in the Unity Editor.

Other developer notes

When using Unity 2017.2.1p2 and the .NET 4.6 API (Experimental) player settings I tried the system ClientWebSocket. While this initially had some success the problem was that after 3 mins or so the following error would occur on the async/await connect function in the Unity Editor:

ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'

Therefore I opted for WebSocket-Sharp which targets .NET Framework 3.5 and works in the Unity 2017 editor and doesn't seem to have the same issue.

Questions or tweet @deadlyfingers

About

Web Socket client for Unity

github.com/Unity3dAzure/UnityWebSocketDemo

Topics

unitywebsockets

Resources

Readme
MIT license
Activity
Custom properties

Stars

51 stars

Watchers

3 watching

Forks

6 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.