How JavaScript Program Can Communicate With C# Console Application? - javascript

I'm trying to write a program that is composed of two parts. The logic part that I prefer to write in C# language because it's object oriented and more important it's the language witch I know the best among objective languages, and the graphic part witch I want to write it with Html, Css and JavaScript and again because they're the most familiar graphical languages witch I can use. Now my question is that how can I transfer data between a C# console app and a JavaScript browser app.
Any help will be appreciated.
Edit:
I must clarify that I just need C# console app and not a web app or web api, and therefor this part is not a backend project. And I need to run these two program separately and want them to communicate with each other.

What you describe should be a full stack application to be honest
With ASP.NET you create your C# backend, setup controllers which handle the interaction between backend code and the front end, and then on the front end you can utilize both Razor markup for HTML templating alongside standard Javascript.
With Blazor web apps, you can take it a step further and have your backend code compile to web assembly and execute directly on the client engine, but it also integrates javascript interop as well. Just be mindful about whether you want a client side or server side Blazor app, as each do things a certain way and are meant for different use cases
What you describe though, sounds more precisely like you want a seperate javascript app, which should be in communication with an ASP.NET Web API. This way you create your backend and api endpoints, which the javascript app can then make requests against. You can start your research for that with MS's tutorial here
The dotNet command line tools can generate solutions for all of these, an ASP.NET fullstack web app, ASP.NET Web API solution, as well as the various blazor app options. And of course, the standard IDE's like Visual Studio and Rider can create these solutions as well

If you're looking to have direct interop, blazor might be what you're looking for.
https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-javascript-from-dotnet?view=aspnetcore-6.0

Related

Running and interacting with a Java program within a web application

I have a Java program that has some input and output displayed through the monitor, and I want to create a web application that can run the Java program with some inputs and then receive any outputs from the program and display them using some JS functions, and I'm wondering how I could go about doing something like that.
I essentially want to create a GUI for my Java program using html/css and JavaScript.
I have already made a static webpage using html/JS that has the appropriate inputs, now I need to figure a way to start the Java program with those inputs and evaluate the outputs.
That's.. generally not how its done.
Instead you run a JVM (a java app) that keeps running and answers web requests itself. In other words, write a webapp. In java.
For example, by using Dropwizard, spark, etc - one of the many, many web frameworks for java.
Your web service can just answer in JSON, keep things simple, no problem. You can also set up your apache, nginx or whatever it is to redirect most calls to your usual web frameworks, and some subset to your jvm webserver that is otherwise 'hidden' from outside view (firewalled off).

Is it possible to show a WPF Application on a html file in my Nodejs application

A few friends of mine and me started to work on a school project, which mainly focuses on Speech Analysis. They wanted to make an application in WPF and I tried to do the Analysis in different programming languages. Mainly C#, Python and JavaScript. I found the perfect way to analyze the Speech-Input in a way we wanted it, but the Programm is written in JavaScript, running in a Nodejs Server.
I searched for a way to implement the Nodejs Server in C# but had some difficulties, so I looked around and found EdgeJs which works the other way around.
Basically making it possible work with .Net and C# Code in JavaScript.
All I really need to do is call functions from my Nodejs application within the C# Code.
The problem is, I have no idea how to get a whole WPF application into the NodejS application, i only found examples with console applications.
Would really aprreciate your input and maybe you know a way to solve my problem :)
Have you thought of making a Webservice for your C# application and then calling your C# functions using Node and AJAX via the webservice
Depending on the input/output you're looking for, you could add some Restful Web Api endpoints to your Node application/server. These rest endpoints will call the speech-analysis functions internally, and then return the results.
If you run your WPF app on the same machine as your node server, you should be able to easily make calls to the API and get the results you are looking for.

Julia as Server side

I need to make a web page where the input and the output is displayed, but the code where I "do stuff" must be in writing in Julia, how can I do this?.
to be clear, I want something like this:
Web ----> Julia ----> Web
|input | do stuff | output
I don't know what I need to make this possible, I need any kind of Server-side?
I'm a very novice in programming, so I don't know how to search this on internet, I will be thankful with any help.
In addition to the Julia webstack, you might want to look into Genie.jl. It's looking like a nice framework and was used to build this website.
If you need to accept input from the web and then output corresponding data after processing it with Julia, then definitely you need to use some form of server side Julia, since Julia does not run in the browser.
In terms of workflow, what you need is very simple:
1/ first, you need to display a form, to accept user input;
2/ second, the form needs to be POST-ed back to the server - where the data in the payload is processed;
3/ finally, you need to send back a response.
You can use a Julia framework like Genie (author of Genie writing this, btw) to have everything Julia in your stack - or you can use some other web stack (PHP, ruby, python, etc) for 1/ and 3/ and have a local Julia script process the data, invoked by the web scripts.
If you don't have experience developing web apps but have/need Julia skills, you're probably better off using Genie. It knows how to render HTML, it provides a nice MVC workflow, has a clear file structure and comes with some generators, does input sanitization in the persistence layer, etc. And it's very easy to accept input, add your data processing logic, and output your response.
But I must warn you that it's still very much work in progress - and this is visible in the state of the documentation (working on it, but boy this is time consuming). You can give it a try and open up issues in GitHub if you get stuck. Also, I would not recommend it for any mission critical apps yet - it needs more testing.
I will copy part of the answer from: How to make a GUI in Julia?, and add a few more.
If you are developing you code within an [Jupyter/IJulia] notebook,
and need very simple interaction, such as slider to change some input
values, the Interact package is the easiest thing to get started
with.
To develop full fledged web UIs, take a look at Escher.
Inspired by the Elm, it provides a functional library of UI
components. Interactive web UIs are created in 100% Julia. There is
no differentiation in code between the client and server sides. The
framework handles all of that.
Another web framework worth looking at
is Genie, which based on the traditional MVC design pattern. It also
includes an ORM. An example of an application written in Genie is
this listing of Julia packages: http://genieframework.com/packages
If you application is relatively simple, and you are happy working with a slightly lower level API, the Mux.jl middleware framework (which Escher uses) allow you to write simple handlers to http requests.
If you want to create cross platform desktop apps, but want to work with
web technologies (i.e. HTML/CSS/Javascript), use Blink. This is a
Julia wrapper around the Electron. You could potentially write an
Escher or Genie application, and wrap in in Blink.jl to create a desktop app.
All of these packages are currently useful and well maintained. Unfortunately, some of the higher level frameworks in juliawebstack are no longer maintained.

Serve PyQt4 GUIs in Web-Application using HTML/CSS/JavaScript

Currently, we have a number of GUIs that have been developed using PyQt4 and PyQtGraph.
We need to make these interfaces accessible to a number of remote users and are hoping to do so by serving the GUIs through an HTML/CSS/JavaScript Web-Application.
The link below provides a few suggestions for this task, but these seem to apply to a project that is in its initial stages of creation. I'm familiar with the development of Python-JavaScript Web-Applications using the Pyramid Server and would like to use this same method for providing users access to PyQt4 GUIs that have already been developed.
https://softwareengineering.stackexchange.com/questions/109572/can-i-create-a-desktop-python-gui-application-and-run-it-as-a-web-app
So my question is, can I serve a functional PyQt4 GUI as a widget using HTML/CSS/JavaScript?
This is hard. In theory you could use a VNC-like approach that sends an image of the window to the client browser and sends user events back to the server. This will probably have poor interactivity depending on the networking and would require a lot of server power, depending on the number of users. (For an example of this, see: https://github.com/campagnola/webqt)
You're probably better off distributing the application with something like py2exe, py2app, cx_freeze, etc.
I personally haven't tried it but you could look into Wt: http://www.webtoolkit.eu/wt/
It is a C++ framework that has a Qt flavour. It has a Java version called JWt. Hence, a Jython binding exists for us Python programmers: http://www.webtoolkit.eu/wt/other_language
It is not a direct replacement of Qt, and might need modification to your Qt code to work as a Wt web app, but it certainly seems worth it to look into.

Avoiding writing the same algorithm in multiple different languages

I am a web developer, and I have observed that many times I need the same function on both client and server. So I write it in JS as well as in PHP or whichever server side language. I am fed up with this. If I have to change it then I need to change it in both places. If I want to use it for some hand held devices, then I will have to rewrite that code yet again using objective-C or Java etc. Then if I need to change that function then I will need to change it everywhere.
Is there a solution for this? If I will call some webservice via ajax, then the client will have a delay. If it will be in JS then it can't be accessed from within PHP or Java, etc. If I use some service in PHP from another language then that can also become a performance issue.
It is also possible that some time we need such functions output from some paramters as input using db or without db.
I know there would be some pretty simpler solution but I am not aware of that. Please tell some language independent solution as I don't have VPS always.
I am not sure if my question actually belongs to stackoverflow.com or programmers.stackexchange.com so please transfer it to programmers.stackexchange.com instead of closing this question if it belongs to there.
Typically, the solution to this problem is to write common code in one language and use translators or library linking to allow access from other languages.
Node.js allows you to write server-side code in JavaScript.
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
You can also use JavaScript to write HTML5 apps for mobile devices.
"Building iPhone Apps with HTML, CSS, and JavaScript"
Now web designers and developers can join the iPhone app party without having to learn Cocoa's Objective-C programming language. It's true: You can write iPhone apps quickly and efficiently using your existing skills with HTML, CSS, and JavaScript. This book shows you how with lots of detailed examples, step-by-step instructions, and hands-on exercises.
If you don't want to try to write large complex applications in JavaScript, GWT provides a way to write Java and via-translation, run it on the client.
The GWT SDK contains the Java API libraries, compiler, and development server. It lets you write client-side applications in Java and deploy them as JavaScript.
If you develop in .Net languages: C# -> JavaScript ScriptSharp
Script# is a free tool that enables developers to author C# source code and subsequently compile it into regular script that works across all modern browsers
you could use the spidermonkey extension to translate php into javascript. this way you can write your functions in php then simply convert them to javascript and re-use them at the browser.
here is a good tutorial to show you how this is done

Categories