I created a NodeJS server on my W10 PC, but I would like to send the data from there to a printing application (on the same PC) created by the C# Windows form application. What should I do?
My idea is to have the printing app have HTTP server function and send the data from NodeJS server via POST communication. I looked into some of these sites, but it was difficult for me and I could only understand the content in fragments.
Please let me know if there are any sites or technical information that beginners (visualstudio/c# study period is about half a year) can understand.
As a way to deliver data to Windows form applications, other than HTTP communication, how about creating an FTP server or shared folder and passing the file over?
Node.js app -->FTP server/shared folder -->Windows form app
Another variation is that you can query the Node.js app from the Windows form app for new files.The Node.js app at this time is an image that returns a file as an HTTP response when there is a file, or an HTTP code 404 when there is no file.
Windows form app-->(POST or GET)-->Node.js app
Both of the ideas that I've come up with this time, the Windows form app periodically checks for new files.If you check more frequently, it will be real-time-style, but if you get too many inquiries, FTP servers, shared folders, and Node.js apps may not be able to handle the load.If you want to try this idea, I recommend that you check it slowly.
Note:
Both applications are running on the same computer.
If that's the case, I think I can exchange files with local folders instead of FTP servers or shared folders.
If you use the [self-host] method of ASP.NET Core HTTP server in the Windows application,
You will be able to receive HTTP POST data.
The components used for .NET Framework 4 and .NET Core are slightly different.
I referred to the .
Add Microsoft.AspNet.WebApi.OwinSelfHost
nuget package
Program.cs
static class program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STATHREAD]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string baseAddress="http://localhost:9000/";
// Start OWIN host
using(WebApp.Start<Startup>(url:baseAddress))
{
// Create HttpClient and make a request to api/values
HttpClient client = new HttpClient();
var response=client.GetAsync(baseAddress+"api/values").Result;
Console.WriteLine(response);
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
mainForm = newForm1();
Application.Run(mainForm);
}
}
public static Form 1 mainForm;
}
public class startup
{
// This code configurations Web API.The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void configuration (IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults:new {id=RouteParameter.Optional}
);
appBuilder.UseWebApi(config);
}
}
public class ValuesController:ApiController
{
// GET api/values/5
public string Get (string name)
{
Program.mainForm.InvokeAddMessage("get"+name);
return "hello" + name;
}
// POST api/values
public void Post (FromBody) US>string value)
{
Program.mainForm.InvokeAddMessage(value);
}
}
Rewrite
Visit Form1.cs to
public void InvokeAddMessage (string value)
{
if(this.InvokeRequired)
{
This.Invoke((MethodInvoker)delegate {InvokeAddMessage(value);});
}
else
{
this.textBox1.Text=value;
}
}
Add a method
http://localhost:9000/api/Values/test
Open to Windows Form
in the Windows Formhello test
appears.
Forhttps://github.com/tonysneed/Demo.DotNetSelfHost
You can use the sample in to create it.
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.