//if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address) //open Index.html to run the client static void Main(string[] args) { //generate js code File.WriteAllText($"./Site/{nameof(NumericService)}.js", RPCJs.GenerateCallerWithDoc <NumericService>()); File.WriteAllText($"./Site/{nameof(TextService)}.js", RPCJs.GenerateCallerWithDoc <TextService>()); //start server and bind its local and remote APIs var cts = new CancellationTokenSource(); var t = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, wc) => { var path = wc.RequestUri.AbsolutePath; if (path == "/numericService") { c.Bind(new NumericService()); } else if (path == "/textService") { c.Bind(new TextService()); } }); Console.Write("{0} ", nameof(MultiService)); Process.Start(new ProcessStartInfo(Path.GetFullPath("./Site/Index.html")) { UseShellExecute = true }); AppExit.WaitFor(cts, t); }
public static void Main(string[] args) { //generate js code File.WriteAllText($"./Site/{nameof(ReportingService)}.js", RPCJs.GenerateCallerWithDoc <ReportingService>()); WebHost.CreateDefaultBuilder(args) .UseStartup <Startup>() .Build() .Run(); }
//if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address) //open Index.html to run the client static void Main(string[] args) { //generate js code File.WriteAllText($"./Site/{nameof(TaskAPI)}.js", RPCJs.GenerateCallerWithDoc <TaskAPI>()); //start server and bind its local and remote API var cts = new CancellationTokenSource(); var t = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) => { c.Bind <TaskAPI, IProgressAPI>(new TaskAPI()); c.BindTimeout(TimeSpan.FromSeconds(1)); //close connection if there is no incommming message after X seconds }); Console.Write("{0} ", nameof(ClientJs)); Process.Start(new ProcessStartInfo(Path.GetFullPath("./Site/Index.html")) { UseShellExecute = true }); AppExit.WaitFor(cts, t); }
//if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address) //open Index.html to run the client static void Main(string[] args) { //generate js code (the API is empty) File.WriteAllText($"./Site/{nameof(PlatformInfo)}.js", RPCJs.GenerateCaller <PlatformInfo>()); //start server and bind its local and remote API var cts = new CancellationTokenSource(); var t = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) => { var pInfo = new PlatformInfo(); c.Bind <PlatformInfo, IBrowserInfo>(pInfo); c.OnOpen += pInfo.InitializeAsync; }); Console.Write("{0} ", nameof(ClientInfoJs)); Process.Start(new ProcessStartInfo(Path.GetFullPath("./Site/Index.html")) { UseShellExecute = true }); AppExit.WaitFor(cts, t); }
//if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address) //open Index.html to run the client static void Main(string[] args) { Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); Connection.MaxMessageSize = 1 * 1024 * 1024; //1MiB RPC.AddConverter(new JpgBase64Converter()); //generate js code File.WriteAllText($"../../Site/{nameof(ImageProcessingAPI)}.js", RPCJs.GenerateCallerWithDoc <ImageProcessingAPI>()); //start server and bind its local and remote API var cts = new CancellationTokenSource(); var t = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) => c.Bind(new ImageProcessingAPI())); Console.Write("{0} ", nameof(Serialization)); Process.Start(new ProcessStartInfo(Path.GetFullPath("../../Site/Index.html")) { UseShellExecute = true }); AppExit.WaitFor(cts, t); }
//if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address) //open Index.html to run the client static void Main(string[] args) { //set message limit Connection.MaxMessageSize = Connection.Encoding.GetMaxByteCount(40); //generate js code File.WriteAllText($"./Site/{nameof(MessagingAPI)}.js", RPCJs.GenerateCaller <MessagingAPI>()); //start server var cts = new CancellationTokenSource(); var t = 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"); c.OnClose += (s, d) => Task.Run(() => Console.WriteLine("Connection closed: " + d)); c.OnError += e => Task.Run(() => Console.WriteLine("Error: " + e.Message)); c.OnReceive += async msg => { Console.WriteLine("Received: " + msg); await c.SendAsync("Server received: " + msg); if (msg.ToLower() == "close") { await c.CloseAsync(statusDescription: "Close requested by user."); } }; }); Console.Write("{0} ", nameof(RawMsgJs)); Process.Start(new ProcessStartInfo(Path.GetFullPath("./Site/Index.html")) { UseShellExecute = true }); AppExit.WaitFor(cts, t); }