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