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:
parent
b3f0cc647f
commit
2b81fbc468
7 changed files with 64 additions and 11 deletions
|
@ -1,10 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
namespace Nibriboard
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,47 @@
|
||||||
using System;
|
using System;
|
||||||
|
using IotWeb.Common.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
namespace Nibriboard
|
namespace Nibriboard
|
||||||
{
|
{
|
||||||
public class NibriWebSocketClient
|
public class NibriWebSocketClient : IWebSocketRequestHandler
|
||||||
{
|
{
|
||||||
|
WebSocket client;
|
||||||
|
|
||||||
public NibriWebSocketClient()
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<Command>
|
<Command>
|
||||||
<type>BeforeBuild</type>
|
<type>BeforeBuild</type>
|
||||||
<command>npm run build</command>
|
<command>npm run build</command>
|
||||||
<workingdir>${ProjectDir}\Client</workingdir>
|
<workingdir>${ProjectDir}/Client</workingdir>
|
||||||
</Command>
|
</Command>
|
||||||
</CustomCommands>
|
</CustomCommands>
|
||||||
</CustomCommands>
|
</CustomCommands>
|
||||||
|
@ -56,7 +56,9 @@
|
||||||
<Compile Include="RippleSpace\DrawnLine.cs" />
|
<Compile Include="RippleSpace\DrawnLine.cs" />
|
||||||
<Compile Include="RippleSpace\Reference.cs" />
|
<Compile Include="RippleSpace\Reference.cs" />
|
||||||
<Compile Include="Utilities.cs" />
|
<Compile Include="Utilities.cs" />
|
||||||
<Compile Include="Nibriboard.cs" />
|
<Compile Include="NibriboardServer.cs" />
|
||||||
|
<Compile Include="Log.cs" />
|
||||||
|
<Compile Include="NibriWebSocketClient.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Client\" Exclude="node_modules" />
|
<EmbeddedResource Include="Client\" Exclude="node_modules" />
|
||||||
|
|
|
@ -2,15 +2,16 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using IotWeb.Server;
|
using IotWeb.Server;
|
||||||
using IotWeb.Common.Http;
|
using IotWeb.Common.Http;
|
||||||
|
using System.Net;
|
||||||
namespace Nibriboard
|
namespace Nibriboard
|
||||||
{
|
{
|
||||||
public class Nibriboard
|
public class NibriboardServer
|
||||||
{
|
{
|
||||||
private HttpServer httpServer;
|
private HttpServer httpServer;
|
||||||
|
|
||||||
public readonly int Port = 31586;
|
public readonly int Port = 31586;
|
||||||
|
|
||||||
public Nibriboard()
|
public NibriboardServer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,10 +23,20 @@ namespace Nibriboard
|
||||||
new HttpResourceHandler(
|
new HttpResourceHandler(
|
||||||
Assembly.GetExecutingAssembly(),
|
Assembly.GetExecutingAssembly(),
|
||||||
"Nibriboard",
|
"Nibriboard",
|
||||||
"index.hmtl"
|
"index.html"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
httpServer.AddWebSocketRequestHandler(
|
||||||
|
"/RipplespaceConnection",
|
||||||
|
|
||||||
|
);
|
||||||
httpServer.Start();
|
httpServer.Start();
|
||||||
|
Log.WriteLine("[NibriboardServer] Started on port {0}", Port);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Test()
|
||||||
|
{
|
||||||
|
HttpListener.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ using System.Runtime.Serialization;
|
||||||
namespace Nibriboard.RippleSpace
|
namespace Nibriboard.RippleSpace
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Chunk : IEnumerable<DrawnLine>, IDeserializationCallback
|
public class Chunk : IEnumerable<DrawnLine>, IDeserializationCallback
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace Nibriboard.RippleSpace
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Defaults to chunk-space, but absolute plane-space can also be calculated
|
/// 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).
|
/// is returned).
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class ChunkReference : Reference
|
public class ChunkReference : Reference
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace Nibriboard.RippleSpace
|
||||||
public class DrawnLine
|
public class DrawnLine
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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
|
/// 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
|
/// 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.
|
/// line that was split across multiple chunks can still be referenced.
|
||||||
|
|
Loading…
Reference in a new issue