I have a web server running on a RaspberryPI. The web server is supposed to provide an interface to a program that deals with a connected 3D printing hardware.
How can I create an element on the web page, that triggers via the web server a function inside an already running C program?
More details:
The printer management app is written in C/C++ and runs all the time, providing a few buttons on a touch screen. The web interface will provide an upload button for printing files, a few status informations, and a start/pause/stop button.
I know a lot about C/C++ and the Unix RPC or named-pipe API. However, I know little about HTML and all the associates ways of scripting and communicationg with the web server.
What is the best approach to implement the start/stop button on the web page, so that a function inside my printer controller is triggered, and secondly, how can I get data back from the printer controller onto the web page?
Thanks!
Related
I have developed a web app that uses Nextjs app for the frontend and a Python (Django) API server as the backend. Most of my front-end pages have API calls to my backend server (in ComponentDidMount or in response to user actions like button clicks).
I want to deploy this app to my server. I am using Nginx as the reverse proxy. The backend deployment is sorted. I am confused about deploying the nextjs app.
After reading the docs I figured there are 2 ways to do this:
Run next build and then next start. This will start a nodejs server on port 3000. I can channel traffic to this port using Nginx.
Run next export. This will generate an out directory. I can channel incoming traffic to this directory using a reverse proxy like Nginx.
Which of the 2 options should I use? What are the differences?
Answering my own question with the help of the answer I received on the NextJS discussions forum link here
Basics of next build, start and export
next build builds the production application in the .next folder. You need to run this command irrespective of whether you want to run next start or next export.
After building, next start starts a Node.js server that supports hybrid pages, serving both statically generated and server-side rendered pages.
next export will export all your pages to static HTML files that you can serve with any host. This is similar to what create-react-app does, but you can still build dynamic pages at build-time with exportPathMap.
Note: Statically generated pages, using next export, are still reactive i.e. any dynamic JS code, which updates your pages at run time, will continue to run as usual (like any other ReactJS app). Next.js will hydrate your application client-side to give it full interactivity. Its just that the dynamic section of the page will only be rendered in the browser at run time and hence it won't be available to search engine crawlers.
When to use next export?
next export is recommended if you have some dynamic pages which need to some data to be fetched only at 'build' time. It is perfect for pages like landing pages, blogs, news articles etc, or for other kinds of pages which are updated only during code builds. You can setup a background task to build your code at regular intervals if your page data needs to be updated more frequently. This will speed up your 'first paint' speed and also provide the entire page data to search engine crawlers for indexing.
When to use next start?
If you do not need any data fetching at build time i.e. your pages are rendered dynamically at run time then you should use next build and then next start. This will also generate static HTML for sections of your page which are not dynamic. This will speed up the 'first paint' time of your pages. See this Automatic Static Optimization.
next export, also produces an optimized production ready build, but it builds fully static app, which means only html, css and javascript but no server-side code.
Since there is no server side code, you do not need a server to host your app. This makes hosting your app easier and cheaper because you dont need to maintain and scale a server. There are plenty of hosts in the market which offers very good pricing.
Since next export builds a static app, it means you cannot use api routes, server-side functions therefore you cannot revalidate. Revalidation means, your app will be checking database for a certain of time that you specify. Let's say you have a blogging app, you save your blog posts to database, with server side coe, you get those on server side, pass them to the client and client renders the posts and with revalidation option set, your app would automatically check the database if the content changed. Since you cannot use this feature, anytime content of your app changes, you have to redeploy your app.
On my wicket page I have a link that opens a second page in another tab/new window.
Click here for second window
These windows are meant to be used in parallel (e.g. in a two-monitor-environment). But I don't want to spread out different menu entries over both screens, so I want all menu entries to stay on MyFirstPage, even if they should influence MySecondPage only.
My ultimate goal is to click a menu entry on MyFirstPage that results in displaying a new Component on MySecondPage. Is this even possible? How can I obtain a java-reference of MySecondPage inside MyFirstPage or establish some other sort of communication?
Everything I found while researching only applied to modal windows or Wicket 1.4, but MySecondPage is not modal.
Maybe wicket's event bus is an option, see: http://code.google.com/p/wicket-guide/downloads/list - Chapter 15.3 Wicket events infrastructure
You could send the event in MyFirstPage , receive it in your Session or Application and there send it to MySecondPage. Session and Application implement IEventSink: http://ci.apache.org/projects/wicket/apidocs/6.x/org/apache/wicket/event/IEventSink.html
There is WebSocket support in Wicket 6:
http://wicketinaction.com/2012/07/wicket-6-native-websockets/
Basically you need to add WebSocketBehavior to the page to make it available for messages from the server.
On the other hand, you can send messages to the server via Wicket.WebSocket.send("A message sent by the client");
I have never tired it but it sounds very promising.
We have a GWT based thick client like web application. The application is considerably large and has some initial load time.
We would like to send the users of our application e-mail messages with href links that would open up a specific asset in our application. Well this of course has the effect that clicking the link opens up the application again, reloads it which we would like to avoid. Ideally we would like the href link to just signal our application/web page somehow so that we could pick up the event in our application and react to it.
Any ideas how we should approach this or is this even possible ?
Thanks!
You need to use a GWT Hyperlink which is a widget that serves as an "internal" hyperlink. That is, it is a link to another state of the running application. When clicked, it will create a new history frame using History.newItem(java.lang.String), but without reloading the page.
If you are not already using it, information is here on GWT's History mechanism
There seems not to be any elegant solution to send an event from a link to an existing browser window. Few solutions I have encountered this far:
a) Implement a cookie polling solution for the application to poll if a cookie exists or changes. The link points to our server which just sets the cookie and this way informs the running app about the event. Some tricky handling should be implemented with some kind of 2-way protocol between the returned temporary page from server to handle the situation where the application is not (yet) running.
b) The same approach as in solution a) but use html5 local storage for communication. This way the poller is not needed as the local storage fires an event when content changes. This would be a possible solution but is not for me as we have to support older browsers without local storage support.
c) A long polling ajax or a web socket for delivering events from the server to the client. A solution but seems overkill and might require a modern browser for atleast web sockets.
I`m currently developing a gwt application on a embedded device (linux with touchscreen) the server and client is started on the device.
I want my client to detect if it`s on the device or not. Because some screen are not available when connecting remotely
You can make a call to the server first and check there if it was made from remote or local address. A response from server should indicate if show screen "A" or not. Hope this helps.
Deferred binding might be the answer. GWT MobileWebApp sample app uses it to discern the form factor of the target in FormFactor.gwt.xml. In essence you define a property and write a provider which determines its value. You then read the property and deliver the appropriate View (in the MVP sense).
BTW I am developing an app for a similar scenario and I'm thinking of reimplementing my solution: reading a URL query parameter which is only present in the browser on the embedded device. Not too awesome. The aforementioned example should allow better hiding of the embedded platform identifier.
How can i test a wcf service in a browser? I mean if i only enter the url in the browser it should give me only relevent xml
It depends on what type of WCF service you have:
if you're using a WCF REST service (webHttpBinding), then you should be able to just navigate to the service address, e.g. http://yourserver/somedir/service.svc
if you're using anything else, you have a SOAP service, and you cannot test a SOAP service in a web browser - the browser just doesn't understand and speak SOAP. There's however a WCF Test Client app in your C:\ drive somewhere which you can use for that purpose.
Make a test application for it. It can be as simple as having a UI with a bunch of buttons, when you press a button then a certain function exposed by the WCF service is called, you could maybe echo the output to a textblock in the app. You could also have a bunch of input type UI items (textboxes, dropdowns, whatever) so you can select parameters to pass to the WCF function.
If you want to be really classy, then make a set of unit tests for it - this means that you will have to have it hosted somewhere though so that it can be called any time the tests are run.