title: How to use a Websocket client to open a long-lived connection to a URL, using PowerShell V2?
body: <p>I am trying to use PowerShell V2 (testing purposes) to initiate a real-time messaging (rtm) instance with Slack. But according to Slack's FAQ, to connect to their rtm API, I need to use the wss:// protocol via a Websocket client to stream events associated. I am also trying to make it an asynchronous connection (receiving as well as connecting). </p>
  
  <p>This doesn't work :</p>
  
  <pre><code>$webSock = New-Object System.Net.WebSocket.ClientWebSocket
  $client = New-Object System.Threading.CancellationToken
  </code></pre>
  
  <p>One other thing is that I need a function to convert from JSON in PowerShell V2. </p>
  
  <p>I tried using this but it doesn't work too:</p>
  
  <pre><code>function ConvertFrom-Json20([object] $item){ 
      add-type -assembly system.web.extensions
      $ps_js=new-object system.web.script.serialization.javascriptSerializer
  
      #The comma operator is the array construction operator in PowerShell
      return ,$ps_js.DeserializeObject($item)
  }
  </code></pre>