Cleanup sample, #regions, dependencies.
This commit is contained in:
parent
577b074024
commit
07fc434cab
|
|
@ -19,13 +19,14 @@ using System;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Net.Server;
|
using Microsoft.Net.Server;
|
||||||
|
|
||||||
namespace HelloWorld
|
namespace HelloWorld
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
using (WebListener listener = new WebListener())
|
using (WebListener listener = new WebListener())
|
||||||
{
|
{
|
||||||
|
|
@ -35,7 +36,7 @@ namespace HelloWorld
|
||||||
Console.WriteLine("Running...");
|
Console.WriteLine("Running...");
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
RequestContext context = listener.GetContextAsync().Result;
|
RequestContext context = await listener.GetContextAsync();
|
||||||
Console.WriteLine("Accepted");
|
Console.WriteLine("Accepted");
|
||||||
|
|
||||||
// Context:
|
// Context:
|
||||||
|
|
@ -78,9 +79,9 @@ namespace HelloWorld
|
||||||
if (context.IsWebSocketRequest)
|
if (context.IsWebSocketRequest)
|
||||||
{
|
{
|
||||||
Console.WriteLine("WebSocket");
|
Console.WriteLine("WebSocket");
|
||||||
WebSocket webSocket = context.AcceptWebSocketAsync().Result;
|
WebSocket webSocket = await context.AcceptWebSocketAsync();
|
||||||
webSocket.SendAsync(new ArraySegment<byte>(bytes, 0, bytes.Length), WebSocketMessageType.Text, true, CancellationToken.None).Wait();
|
await webSocket.SendAsync(new ArraySegment<byte>(bytes, 0, bytes.Length), WebSocketMessageType.Text, true, CancellationToken.None);
|
||||||
webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Goodbye", CancellationToken.None).Wait();
|
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Goodbye", CancellationToken.None);
|
||||||
webSocket.Dispose();
|
webSocket.Dispose();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
"Microsoft.AspNet.Server.WebListener": "",
|
"Microsoft.AspNet.Server.WebListener": "",
|
||||||
"Microsoft.Net.Server": ""
|
"Microsoft.Net.Server": ""
|
||||||
},
|
},
|
||||||
"commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:8080" },
|
"commands": { "web": "Microsoft.AspNet.Hosting --server=Microsoft.AspNet.Server.WebListener --server.urls=http://localhost:8080" },
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"net45": {
|
"net45": {
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -114,8 +114,6 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IHttpRequestFeature
|
|
||||||
|
|
||||||
Stream IHttpRequestFeature.Body
|
Stream IHttpRequestFeature.Body
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -231,8 +229,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
set { _scheme = value; }
|
set { _scheme = value; }
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
#region IHttpConnectionFeature
|
|
||||||
bool IHttpConnectionFeature.IsLocal
|
bool IHttpConnectionFeature.IsLocal
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -297,8 +294,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
set { _remotePort = value; }
|
set { _remotePort = value; }
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
#region IHttpTransportLayerSecurityFeature
|
|
||||||
X509Certificate IHttpTransportLayerSecurityFeature.ClientCertificate
|
X509Certificate IHttpTransportLayerSecurityFeature.ClientCertificate
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -319,8 +315,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
_clientCert = await Request.GetClientCertificateAsync();
|
_clientCert = await Request.GetClientCertificateAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
#region IHttpResponseFeature
|
|
||||||
Stream IHttpResponseFeature.Body
|
Stream IHttpResponseFeature.Body
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -363,48 +358,33 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
get { return Response.StatusCode; }
|
get { return Response.StatusCode; }
|
||||||
set { Response.StatusCode = value; }
|
set { Response.StatusCode = value; }
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
#region IHttpSendFileFeature
|
|
||||||
|
|
||||||
Task IHttpSendFileFeature.SendFileAsync(string path, long offset, long? length, CancellationToken cancellation)
|
Task IHttpSendFileFeature.SendFileAsync(string path, long offset, long? length, CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
return Response.SendFileAsync(path, offset, length, cancellation);
|
return Response.SendFileAsync(path, offset, length, cancellation);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
CancellationToken IHttpRequestLifetimeFeature.OnRequestAborted
|
||||||
#region IHttpRequestLifetimeFeature
|
|
||||||
|
|
||||||
public CancellationToken OnRequestAborted
|
|
||||||
{
|
{
|
||||||
get { return _requestContext.DisconnectToken; }
|
get { return _requestContext.DisconnectToken; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Abort()
|
void IHttpRequestLifetimeFeature.Abort()
|
||||||
{
|
{
|
||||||
_requestContext.Abort();
|
_requestContext.Abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
bool IHttpOpaqueUpgradeFeature.IsUpgradableRequest
|
||||||
#region IHttpOpaqueUpgradeFeature
|
|
||||||
|
|
||||||
public bool IsUpgradableRequest
|
|
||||||
{
|
{
|
||||||
get { return _requestContext.IsUpgradableRequest; }
|
get { return _requestContext.IsUpgradableRequest; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Stream> UpgradeAsync()
|
Task<Stream> IHttpOpaqueUpgradeFeature.UpgradeAsync()
|
||||||
{
|
{
|
||||||
if (!IsUpgradableRequest)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("This request cannot be upgraded.");
|
|
||||||
}
|
|
||||||
return _requestContext.UpgradeAsync();
|
return _requestContext.UpgradeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
bool IHttpWebSocketFeature.IsWebSocketRequest
|
||||||
#region IHttpWebSocketFeature
|
|
||||||
|
|
||||||
public bool IsWebSocketRequest
|
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
@ -412,7 +392,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<WebSocket> AcceptAsync(IWebSocketAcceptContext context)
|
Task<WebSocket> IHttpWebSocketFeature.AcceptAsync(IWebSocketAcceptContext context)
|
||||||
{
|
{
|
||||||
// TODO: Advanced params
|
// TODO: Advanced params
|
||||||
string subProtocol = null;
|
string subProtocol = null;
|
||||||
|
|
@ -422,7 +402,5 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
return _requestContext.AcceptWebSocketAsync(subProtocol);
|
return _requestContext.AcceptWebSocketAsync(subProtocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@
|
||||||
"Microsoft.AspNet.HttpFeature": "0.1-alpha-*",
|
"Microsoft.AspNet.HttpFeature": "0.1-alpha-*",
|
||||||
"Microsoft.Framework.ConfigurationModel": "0.1-alpha-*",
|
"Microsoft.Framework.ConfigurationModel": "0.1-alpha-*",
|
||||||
"Microsoft.Framework.Logging": "0.1-alpha-*",
|
"Microsoft.Framework.Logging": "0.1-alpha-*",
|
||||||
"Microsoft.Net.Server" : ""
|
"Microsoft.Net.Server" : "",
|
||||||
|
"Microsoft.Net.WebSocketAbstractions": "0.1-alpha-*"
|
||||||
},
|
},
|
||||||
"compilationOptions": {
|
"compilationOptions": {
|
||||||
"allowUnsafe": true
|
"allowUnsafe": true
|
||||||
|
|
@ -16,7 +17,6 @@
|
||||||
"net45": {},
|
"net45": {},
|
||||||
"k10": {
|
"k10": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.Net.WebSocketAbstractions": "0.1-alpha-*",
|
|
||||||
"Microsoft.Win32.Primitives": "4.0.0.0",
|
"Microsoft.Win32.Primitives": "4.0.0.0",
|
||||||
"System.Collections": "4.0.0.0",
|
"System.Collections": "4.0.0.0",
|
||||||
"System.Collections.Concurrent": "4.0.0.0",
|
"System.Collections.Concurrent": "4.0.0.0",
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"version": "0.1-alpha-*",
|
"version": "0.1-alpha-*",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"Microsoft.Net.WebSocketAbstractions": "0.1-alpha-*"
|
||||||
},
|
},
|
||||||
"compilationOptions" : { "allowUnsafe": true },
|
"compilationOptions" : { "allowUnsafe": true },
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"net45" : { },
|
"net45" : { },
|
||||||
"k10" : {
|
"k10" : {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.Net.WebSocketAbstractions": "0.1-alpha-*",
|
|
||||||
"Microsoft.Win32.Primitives": "4.0.0.0",
|
"Microsoft.Win32.Primitives": "4.0.0.0",
|
||||||
"System.Collections": "4.0.0.0",
|
"System.Collections": "4.0.0.0",
|
||||||
"System.Collections.Concurrent": "4.0.0.0",
|
"System.Collections.Concurrent": "4.0.0.0",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue