1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

Start setting up Http server & WebSocket listener

This commit is contained in:
Starbeamrainbowlabs 2017-01-10 19:52:27 +00:00
parent b3f0cc647f
commit 2b81fbc468
7 changed files with 64 additions and 11 deletions

View file

@ -1,10 +1,13 @@
using System;
namespace Nibriboard
{
public class Log
public static class Log
{
public Log()
public static int WriteLine(string text, params object[] args)
{
string outputText = $"[{DateTime.Now}] " + string.Format(text, args);
Console.WriteLine(outputText);
return outputText.Length;
}
}
}

View file

@ -1,10 +1,47 @@
using System;
using IotWeb.Common.Http;
using System.Threading.Tasks;
namespace Nibriboard
{
public class NibriWebSocketClient
public class NibriWebSocketClient : IWebSocketRequestHandler
{
WebSocket client;
public NibriWebSocketClient()
{
}
public void Connected(WebSocket socket)
{
client = socket;
client.DataReceived += async (WebSocket clientSocket, string frame) => {
try {
await onMessage(frame);
}
catch(Exception error) {
await Console.Error.WriteLineAsync(error);
throw;
}
//Task.Run(async () => await onMessage(frame)).Wait();
};
}
/// <summary>
/// Whether we will accept the WebSocket connection or not.
/// </summary>
/// <param name="uri">The uri the user connected to.</param>
/// <param name="protocol">The protocol the user is connecting with.</param>
/// <returns>Whether we want to accept the WebSocket connection attempt or not.</returns>
public bool WillAcceptRequest(string uri, string protocol)
{
Log.WriteLine("[Nibriboard/Websocket] Accepting {0} via {1}.", uri, protocol);
return true;
}
private async Task onMessage(string frame)
{
}
}
}

View file

@ -24,7 +24,7 @@
<Command>
<type>BeforeBuild</type>
<command>npm run build</command>
<workingdir>${ProjectDir}\Client</workingdir>
<workingdir>${ProjectDir}/Client</workingdir>
</Command>
</CustomCommands>
</CustomCommands>
@ -56,7 +56,9 @@
<Compile Include="RippleSpace\DrawnLine.cs" />
<Compile Include="RippleSpace\Reference.cs" />
<Compile Include="Utilities.cs" />
<Compile Include="Nibriboard.cs" />
<Compile Include="NibriboardServer.cs" />
<Compile Include="Log.cs" />
<Compile Include="NibriWebSocketClient.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Client\" Exclude="node_modules" />

View file

@ -2,15 +2,16 @@
using System.Reflection;
using IotWeb.Server;
using IotWeb.Common.Http;
using System.Net;
namespace Nibriboard
{
public class Nibriboard
public class NibriboardServer
{
private HttpServer httpServer;
public readonly int Port = 31586;
public Nibriboard()
public NibriboardServer()
{
}
@ -22,10 +23,20 @@ namespace Nibriboard
new HttpResourceHandler(
Assembly.GetExecutingAssembly(),
"Nibriboard",
"index.hmtl"
"index.html"
)
);
httpServer.AddWebSocketRequestHandler(
"/RipplespaceConnection",
);
httpServer.Start();
Log.WriteLine("[NibriboardServer] Started on port {0}", Port);
}
private void Test()
{
HttpListener.
}
}
}

View file

@ -8,7 +8,7 @@ using System.Runtime.Serialization;
namespace Nibriboard.RippleSpace
{
/// <summary>
/// Represents a single chunk of an infinite <see cref="Nibriboard.RippleSpace.Plane" />.
/// Represents a single chunk of an infinite <see cref="NibriboardServer.RippleSpace.Plane" />.
/// </summary>
[Serializable]
public class Chunk : IEnumerable<DrawnLine>, IDeserializationCallback

View file

@ -8,7 +8,7 @@ namespace Nibriboard.RippleSpace
/// </summary>
/// <remarks>
/// Defaults to chunk-space, but absolute plane-space can also be calculated
/// and obtained (A <see cref="Nibriboard.RippleSpace.LocationReference" />
/// and obtained (A <see cref="NibriboardServer.RippleSpace.LocationReference" />
/// is returned).
/// </remarks>
public class ChunkReference : Reference

View file

@ -9,7 +9,7 @@ namespace Nibriboard.RippleSpace
public class DrawnLine
{
/// <summary>
/// The id of line that this <see cref="Nibriboard.RippleSpace.DrawnLine" /> is part of.
/// The id of line that this <see cref="NibriboardServer.RippleSpace.DrawnLine" /> is part of.
/// Note that this id may not be unique - several lines that were all
/// drawn at once may also have the same id. This is such that a single
/// line that was split across multiple chunks can still be referenced.