title: How to connect javascript and c#
body: <p>I need to connect a javascript/jquery-based webpage (which is executed locally only) using a c# application.</p>
  
  <p>I guess the easiest ways are using a database (what seems to be problematically to connect with from javascript) or a tcp-socket. I tried to create a socket but for some reason I'm stuck. However I was able to create a server running with node.js which sends a "hello world" to c#, but I'm not able to connect to that server with javascript.</p>
  
  <p>My particular use case is a webpage to recognize gestures of a leap motion. The C# part will be run in Unity, which is not able to execute the given javascript files. So the communication between javascript and C# is not used to build the website (which would be the main reason to use asp.net, correct?)</p>
  
  <p>WCF sounds interesting but is there a way to connect with it from javascript?
  My "server" was created with socket.io:</p>
  
  <pre><code>var net = require('net');
  
  var server = net.createServer(function(socket){
      console.log("function called: " + socket.value);
      socket.write('hello\n');
      socket.end('world\n');
  });
  server.listen(8000);
  </code></pre>
  
  <p>I can connect to this server from my c# application, but I don't know how to send a message from javascript. When trying to connect using WebSocket I get the following error:</p>
  
  <pre><code>WebSocket connection to 'ws://127.0.0.1:8000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
  </code></pre>
  
  <p>using io.connect results in:</p>
  
  <pre><code>net::ERR_NAME_NOT_RESOLVED
  </code></pre>
  
  <p>How do I get by those errors to talk to the web application from client-side javascript?</p>