Skip to main content

FM WebSocket 2.0(deprecated)

Description

It’s a Server-Clients networking system for Internet Streaming, which requires node.js server hosting. It supports string and byte[] streaming.


Basic Setup

All the communication between Server, Clients is via FM WebSocket Manager. It requires node.js server for the Internet Streaming, which will route your data in public network. It also requires one Unity3D connection as Server in your whole connection, as it’s Server-Clients based networking system

This package includes example script of a very light-weight node.js server, which you may host it on any Cloud Virtual Machine(linux, windows or mac)

There are two parts in this tutorial setup.

Part A: node.js server

Part B: Unity3D FMWebSocketManager


Part A: Node.js server

Our example server is located in our plugin root folder

/FMWebSocket/TestServer_v2.x.x/Resources/FMWebSocket
  1. Install npm + node.js Download and install necessary items
https://nodejs.org/en/download/
  1. Install express https://expressjs.com/en/starter/installing.html
cmd/terminal: npm init
cmd/terminal: Enter…
cmd/terminal: npm install express –save
  1. Install ws module
cmd/terminal: npm install ws
  1. Finish & Test on localhost

You may follow this step-by-step tutorial, the commands are compatible in Mac/Windows/Linux https://youtu.be/Zjm5KGHyceU


Part B: Unity3D FMWebSocketManager Setup


Setup for Sender Scene(Sender)

  1. Create a new GameObject in your scene, and name it FMWebSocketManager.
  2. Add Component FMWebSocketManager.cs fmetp-stream-fmwebsocket42-addcomponent
  3. Choose NetworkType: Server, Client
  4. enabled Auto Init is recommended, which will automatically start the connection in runtime.
  5. you may also connect them manually as alternative via script. fmetp-stream-fmwebsocket42-networktype

//All node.js server examples are included in our testing zip file
//Server or Client Mode is for Server-Clients networking connection with websocket
FMWebSocketManager.instance.Action_InitAsServer();
FMWebSocketManager.instance.Action_InitAsClient();
//WebSocket Mode is only for standard websocket connection
FMWebSocketManager.instance.Action_InitAsWebSocket();

//For NetworkType: Server/Client
FMWebSocketManager.instance.SendToAll(byte[] _byteData);
FMWebSocketManager.instance.SendToServer(byte[] _byteData);
FMWebSocketManager.instance.SendToOthers(byte[] _byteData);
FMWebSocketManager.instance.SendToTarget(byte[] _byteData, string _wsid);
FMWebSocketManager.instance.SendToAll(string _stringData);
FMWebSocketManager.instance.SendToServer(string _stringData);
FMWebSocketManager.instance.SendToOthers(string _stringData);
FMWebSocketManager.instance.SendToTarget(string _stringData, string _wsid);

//For NetworkType: WebSocket only
FMWebSocketManager.instance.WebSocketSend(byte[] _byteData);
FMWebSocketManager.instance.WebSocketSend(string _stringData);