Added support for websockets

- Upgraded to ASP.NET Core 1.1 preview
This commit is contained in:
David Fowler 2016-10-01 10:26:49 -07:00
parent 40ecc9df4d
commit 9f5ef70164
6 changed files with 53 additions and 6 deletions

View File

@ -8,6 +8,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{83B2C3EB-A3D8-4E6F-9A3C-A380B005EF31}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
NuGet.config = NuGet.config
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{C4BC9889-B49F-41B6-806B-F84941B2549B}"

View File

@ -3,5 +3,6 @@
<packageSources>
<add key="Channels" value="https://www.myget.org/F/channels/api/v3/index.json" />
<add key="dotnet-corefxlab" value="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" />
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
</packageSources>
</configuration>

View File

@ -7,11 +7,11 @@
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0"
"Microsoft.AspNetCore.Diagnostics": "1.1.0-*",
"Microsoft.AspNetCore.StaticFiles": "1.1.0-*",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*",
"Microsoft.Extensions.Logging.Console": "1.1.0-*"
},
"tools": {

View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
document.addEventListener('DOMContentLoaded', () => {
var ws = new WebSocket('ws://localhost:5000/chat/ws');
ws.onopen = function () {
console.log('Opened!');
};
ws.onmessage = function (evt) {
var child = document.createElement('li');
child.innerText = evt.data;
document.getElementById('messages').appendChild(child);
};
ws.onclose = function (evt) {
console.log('Closed!');
};
document.getElementById('sendmessage').addEventListener('click', () => {
let data = document.getElementById('data').value;
ws.send(data);
});
});
</script>
</head>
<body>
<h1>WebSockets</h1>
<input type="text" id="data" />
<input type="button" id="sendmessage" value="Send" />
<ul id="messages">
</ul>
</body>
</html>

View File

@ -9,6 +9,9 @@ namespace Microsoft.AspNetCore.Builder
{
var dispatcher = new HttpConnectionDispatcher(app);
callback(dispatcher);
// TODO: Use new low allocating websocket API
app.UseWebSockets();
app.UseRouter(dispatcher.GetRouter());
return app;
}

View File

@ -2,7 +2,8 @@
"version": "0.1.0-*",
"dependencies": {
"Channels": "0.2.0-beta-*",
"Microsoft.AspNetCore.Routing": "1.0.0"
"Microsoft.AspNetCore.Routing": "1.1.0-*",
"Microsoft.AspNetCore.WebSockets": "0.2.0-*"
},
"frameworks": {
"netstandard1.3": {