Last active
July 2, 2017 11:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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