Beispiel #1
0
 /// <summary>
 /// Disconnect from websocket server.
 /// This function needs to be run on events such as delete the component.
 /// </summary>
 private void disconnect()
 {
     if (this.wscObj != null)
     {
         try { this.wscObj.disconnect(); }
         catch { }
         this.wscObj.changed -= this.wsObjectOnChange;
         this.wscObj          = null;
         this.wsAddress.setAddress(null);
     }
 }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            WsObject wscObj  = new WsObject();
            string   message = "Hello World";

            if (!DA.GetData(0, ref wscObj))
            {
                return;
            }
            if (!DA.GetData(1, ref message))
            {
                return;
            }

            wscObj.send(message);
        }
Beispiel #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.subscribeToEvents();

            string address = null;
            string initMsg = "Hello World";
            bool   reset   = false;

            DA.GetData(0, ref address);
            if (!DA.GetData(1, ref initMsg))
            {
                return;
            }
            if (!DA.GetData(2, ref reset))
            {
                return;
            }

            if (!this.wsAddress.isSameAs(address) || reset)
            {
                this.disconnect();

                this.wsAddress.setAddress(address);

                if (this.wsAddress.isValid())
                {
                    this.wscObj          = new WsObject().init(address, initMsg);
                    this.Message         = "Connecting";
                    this.wscObj.changed += this.wsObjectOnChange;
                }
                else
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid address");
                }
            }

            DA.SetData(0, this.wscObj);
        }