title: Convert C# Websocket example to Unity MonoBehaviour
body: <p>Bit of a C# noob.<br>
  Trying to use the Websocket CSharp library
  <a href="http://sta.github.io/websocket-sharp/" rel="nofollow noreferrer">http://sta.github.io/websocket-sharp/</a>
  to create a socket server in Unity.<br>
  How would I convert the following to a <strong>Monobehaviour</strong> so I can simply attach to a gameobject and run?<br>
  I know obviously I am extending Monobehaviour and I am dealing with <strong>Awake</strong>, <strong>Start</strong> and <strong>Update</strong> methods, but a bit fuzzy when it comes to nested classes, namespaces , what code in the following I would put in my <strong>Start</strong> method, and whether I should keep everything in just one .cs file or break it up, one file per class.</p>
  
  <pre><code>using System;
  using WebSocketSharp;
  using WebSocketSharp.Server;
  
  namespace Example
  {
    public class Laputa : WebSocketBehavior
    {
      protected override void OnMessage (MessageEventArgs e)
      {
        var msg = e.Data == "BALUS"
        ? "I've been balused already..."
        : "I'm not available now.";
  
        Send (msg);
      }
    }
  
    public class Program
    {
      public static void Main (string[] args)
      {
        var wssv = new WebSocketServer ("ws://dragonsnest.far");
        wssv.AddWebSocketService&lt;Laputa&gt; ("/Laputa");
        wssv.Start ();
        Console.ReadKey (true);
        wssv.Stop ();
      }
    }
  }
  
  
  using WebSocketSharp;
  using WebSocketSharp.Server;
  
  namespace Example
  {
    public class Laputa : WebSocketBehavior
    {
      protected override void OnMessage (MessageEventArgs e)
      {
        var msg = e.Data == "BALUS"
        ? "I've been balused already..."
        : "I'm not available now.";
  
        Send (msg);
      }
    }
  
    public class Program
    {
      public static void Main (string[] args)
      {
        var wssv = new WebSocketServer ("ws://dragonsnest.far");
        wssv.AddWebSocketService&lt;Laputa&gt; ("/Laputa");
        wssv.Start ();
        Console.ReadKey (true);
        wssv.Stop ();
      }
    }
  }
  </code></pre>