title: How to emit events from Node-Red to a Unity client with node-red-contrib-socketio
body: <p>I'm trying to use node-red-contrib-socketio package to emit a 'weather' event from Node-Red to a client based on input from Weather Underground.</p>
  
  <p><img src="https://i.stack.imgur.com/0XEmN.jpg" alt="Emit Weather Event from Node-Red"></p>
  
  <p>I'm using the following code in a node-red function to process the input from WeatherUnderground and set the event:</p>
  
  <p><img src="https://i.stack.imgur.com/3eqEi.jpg" alt="Setting &#39;weather&#39; event"></p>
  
  <pre><code>weather = msg.payload.weather;
  msg.payload = {weather: weather};
  msg.socketIOEvent = 'weather';
  RED.util.setMessageProperty(msg, "socketIOEmit", "emit", true);
  return msg;
  </code></pre>
  
  <p>Is this the correct way to set and emit the weather event?</p>
  
  <p>For reference:</p>
  
  <p>I've bound the SocketIO Out node to Node_Red (so presumably port 1880 on local host). I'm using the Unity game engine as the client to receive the event with the Socket.IO library from the asset store: <a href="https://assetstore.unity.com/packages/tools/network/socket-io-for-unity-21721" rel="nofollow noreferrer">https://assetstore.unity.com/packages/tools/network/socket-io-for-unity-21721</a> </p>
  
  <p>Unity is listening for the weather event on the following URL: </p>
  
  <pre><code>ws://127.0.0.1:1880/socket.io/?EIO=4&amp;transport=websocket
  </code></pre>
  
  <p>Currently Unity seems to be registering the connection but not the emitted weather event.</p>
  
  <p>My test C# script for handling the events in Unity is as follows:</p>
  
  <pre><code>using UnityEngine;
  using SocketIO;
  
  public class NodeNetwork : MonoBehaviour
  {
  
      //Reference socket component
      static SocketIOComponent socket;
  
      void Start()
      {
          //Initialise reference to socket component
          socket = GetComponent&lt;SocketIOComponent&gt;();
          //Register callbacks for network events
          socket.On("open", OnConnected);
          socket.On("weather", OnWeather);
      }
  
      //Create a callback for the connection
      void OnConnected(SocketIOEvent e)
      {
          Debug.Log("Connected");
          //Emit a move call back to the server 
          socket.Emit("client connected");
      }
  
      //Create a callback for receipt of weather events
      void OnWeather(SocketIOEvent e)
      {
          Debug.Log("New weather event received" + e.data);
          socket.Emit("weather received");
      }
  
  }
  </code></pre>
  
  <p>Any advice would be appreciated.</p>