This repository has been archived by the owner on Dec 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancing samples, restorign raw messaging support, bug fixing.
- Loading branch information
Showing
18 changed files
with
235 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using WebSocketRPC; | ||
|
||
namespace RawMsgJs | ||
{ | ||
//Empty class (would contains methods if RPC was used). | ||
class MessagingAPI | ||
{ } | ||
|
||
class Program | ||
{ | ||
//if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'ocalhost', add for public address) | ||
//open Index.html to run the client | ||
static void Main(string[] args) | ||
{ | ||
//set message limit | ||
RPCSettings.MaxMessageSize = RPCSettings.Encoding.GetMaxByteCount(40); | ||
|
||
//generate js code | ||
File.WriteAllText($"./Site/{nameof(MessagingAPI)}.js", RPCJs.GenerateCaller<MessagingAPI>()); | ||
|
||
//start server | ||
var cts = new CancellationTokenSource(); | ||
var s = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) => | ||
{ | ||
//set idle timeout | ||
c.BindTimeout(TimeSpan.FromSeconds(30)); | ||
|
||
c.OnOpen += async () => await c.SendAsync("Hello from server using WebSocketRPC", RPCSettings.Encoding); | ||
c.OnClose += () => Console.WriteLine("Connection closed."); | ||
c.OnError += e => Console.WriteLine("Error: " + e.Message); | ||
|
||
c.OnReceive += async (msg, isText) => | ||
{ | ||
var txt = msg.ToString(RPCSettings.Encoding); | ||
Console.WriteLine("Received: " + txt); | ||
await c.SendAsync("Server received: " + txt, RPCSettings.Encoding); | ||
|
||
if (txt.ToLower() == "close") | ||
await c.CloseAsync(statusDescription: "Close requested by user."); | ||
}; | ||
}); | ||
|
||
Console.WriteLine("Running: '{0}'. Press [Enter] to exit.", nameof(RawMsgJs)); | ||
Console.ReadLine(); | ||
cts.Cancel(); | ||
s.Wait(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.0;net47</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<OutputPath>bin\</OutputPath> | ||
<ApplicationIcon /> | ||
<OutputType>Exe</OutputType> | ||
<StartupObject /> | ||
|
||
<DocumentationFile>bin\$(TargetFramework)\ServerClientJs.xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Site\LocalAPI.js" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Source\WebSocketRPC.JS\WebSocketRPC.Js.csproj" /> | ||
<ProjectReference Include="..\..\Source\WebsocketRPC.Standalone\WebsocketRPC.Standalone.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Site\Index.html"> | ||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<html> | ||
<head> | ||
<script src="MessagingAPI.js"></script> | ||
</head> | ||
|
||
<body> | ||
<p>Send/receive messages. Message is sent when the text box loses the focus.</p> | ||
<hr /> | ||
|
||
<label>Message: </label> <input type="text" id="msg" onblur="onRequest(this)" disabled/> | ||
|
||
<p>Responses:</p> | ||
<div id="responses"></div> | ||
|
||
<script> | ||
function onConnect() | ||
{ | ||
var elem = document.getElementById("msg"); | ||
elem.disabled = false; | ||
} | ||
|
||
function onRequest(elem) | ||
{ | ||
api.send(elem.value); | ||
elem.value = ""; | ||
} | ||
|
||
function onResponse(msg, color) | ||
{ | ||
color = color || 'black'; | ||
|
||
var p = document.createElement('p'); | ||
p.innerHTML = msg; | ||
p.style.color = color; | ||
|
||
var lst = document.getElementById("responses"); | ||
lst.appendChild(p); | ||
} | ||
|
||
function writeMsg(jsonMsg, color) | ||
{ | ||
onResponse(JSON.stringify(jsonMsg, null, "\t"), color); | ||
} | ||
|
||
//init API | ||
var api = new MessagingAPI("ws://localhost:8001"); | ||
api.onOtherMessage = onResponse; | ||
api.connect(onConnect, err => writeMsg(err, 'red'), msg => writeMsg(msg, 'green')); //onConnect, onError, onClose | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.