UnityWebSocket.unitypackage file from Releases page.
Import it into your Unity project.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();
More detail usages, see the UnityWebSocketDemo.cs code in project.
Menus
Unity Define Symbols(Optional):
UNITY_WEB_SOCKET_LOG Open internal log info.UNITY_WEB_SOCKET_ENABLE_ASYNC Use network thread handle message (not WebGL platform).