Skip to content

Instantly share code, notes, and snippets.

@ksasao
Last active July 2, 2017 11:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ksasao/45e08c0951410bbe8ecb to your computer and use it in GitHub Desktop.
Save ksasao/45e08c0951410bbe8ecb to your computer and use it in GitHub Desktop.
Edge.js ( https://github.com/tjanczuk/edge ) をつかって C# で Node.js の HTTPサーバをホストするサンプルコード。nuget で Edge.js をインストールしてください。.NET Framework 4.5 または Mono 3.4.0 が必要です。License: WTFPL 実行結果: https://twitter.com/ksasao/status/546691740199960576
using EdgeJs;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace EdgeJsTest
{
class Program
{
public static async void Start()
{
var createWebSocketServer = Edge.Func(@"
var http = require('http');
return function (port, cb) {
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
res.end('こんにちは。Hello, world! ');
console.log(new Date());
}).listen(port, cb);
};
");
await createWebSocketServer(8080);
}
static void Main(string[] args)
{
Task.Run((Action)Start);
new ManualResetEvent(false).WaitOne();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment