Porting Freebasic fltk-c application to web based

General FreeBASIC programming questions.
Post Reply
dbickin
Posts: 59
Joined: Aug 03, 2005 16:40

Porting Freebasic fltk-c application to web based

Post by dbickin »

Okay, this may be off-topic, but I have written a few small applications in freebasic, using fltk-c to create a user interface to view and modify data in a database.

I would like to change these programs so that they run on a web server in a browser.

Currently, I have the programs on a usb stick, compiled under linux and windows so I can attach the usb and run the approriate program on each of my computers. But since my phone doesn't have a full sized usb port it is out of the loop. I figrue it the program ran in a browser, it would run on all of my devices.

I suspect I will have to give up freebasic as the language used, but is that correct? I have seen posts about running freebasic programs with cgi(*), but they seemed to be non-interactive. I want something interactive.

I last worked with html a few decades ago, and most of that is obsolete as it predated css.

So my questions are:
(1) Is there a direct/easy way to port my freebasic appliation using fltk to interact with a web service? If so, what google search terms would I use to learn the details?
(2) Assuming I will have to do a complete rewrite, what language/toolkit/framework would best leverage my existing freebasic and fltk knowledge? Again, what search terms would best lead me to knowledge to learn my options?

Thanks,
David

(*) To illustrate my frustration, I double checked that I was using cgi correctly above, but my google search for cgi ONLY returned its usage as "computer generated images". Only by searching fastcgi, did I get links for cgi as "common gateway interface".
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Porting Freebasic fltk-c application to web based

Post by caseih »

dbickin wrote:I suspect I will have to give up freebasic as the language used, but is that correct? I have seen posts about running freebasic programs with cgi(*), but they seemed to be non-interactive. I want something interactive.
HTTP is by design non-interactive. Or more precisely it's stateless. You connect, give it arguments, it gives you a page (or some data). To make a web app interactive you use javascript in your page, and use cookies to track state, and make requests of the back end. So you certainly can make an "interactive" web app with FB running as a CGI. But you'll still will need to use javascript in your CGI-generated html.

CGI is a protocol, and you can use any language, provided you implement the protocol which is pretty simple. It mainly involves environment variables (ENVIRON in FB), reading text from standard in, processing it to extract http headers and form variables, cookies, etc, and then writing html code to standard out. When an http request for the CGI comes in, it runs your program until it ends, then transmits the output to the client. You'll have to invent your own way of storing data on your server and remembering clients between runs of the program. Many languages (FB possibly even) have libraries for making that easier. FastCGI is an advancement on CGI where your CGI program does not quit but keeps running in a loop until a new request comes it. This is much faster and maybe easier than pure CGI. I have no experience in it
I last worked with html a few decades ago, and most of that is obsolete as it predated css.
Yes web development now is super complicated and requires using several languages all at the same tim.
So my questions are:
(1) Is there a direct/easy way to port my freebasic appliation using fltk to interact with a web service? If so, what google search terms would I use to learn the details?
Maybe? Someone posted not that long ago about some FB programs they compiled using emscripten that ran inside the browser. It's not easy to get going, though, and the result may not be all that wonderful on a phone screen. See viewtopic.php?t=29005. Not sure fltk will work though.

Generally-speaking, it's not easy to go from a desktop app to a web-based app. The way the apps are developed and the way the user interface is done is usually completely different.
(2) Assuming I will have to do a complete rewrite, what language/toolkit/framework would best leverage my existing freebasic and fltk knowledge? Again, what search terms would best lead me to knowledge to learn my options?
It depends I suppose. Programming concepts are going to be the same. Logic, variables, etc. But sadly I don't think very much translates across directly. Compared to desktop application development, web apps require learning new tools. You certainly can make CGI programs with FB, but you'll still need to get comfortable with a web server, html5, CSS, and javascript.

Given the way web apps are built, there are good reasons why, except for Java, compiled languages are not common on the Web. Interpreted languages are much faster to iterate through the design, coding, and debug process. And since most web stuff is i/o bound, pure CPU doesn't matter quite as much.

Or you could go in a completely different direction and try tools in other languages, like Kivy, which lets you make portable applications in Python that can run on a desktop or on a phone as an installable app. Also there is QtQuick which lets you make computer and phone apps in Javascript, and might even run in a browser.

Also you could learn native app development in Android or iOS using their respective tools.

There are many other options out there, but most of them do not involve FB.

I'm very much not a web developer and do not want to be. But I can see why everything has gone in that direction.
Julcar
Posts: 141
Joined: Oct 19, 2010 18:52
Contact:

Re: Porting Freebasic fltk-c application to web based

Post by Julcar »

I think there is a misconception about what FreeBasic can do and how could do it...

I've been working with FreeBasic and CGI as soon as I learned how to use it (circa 2013), and my efforts are being saved into my project IguanaCMS

First of all, you won't need any fltk-c library, CGI applications are managed as a console app, and the web browser output is the interface itself.
Second, you will have to rewrite any logic that handle form events, to handle instead POST and GET parameters, because that is the way you can interact with your application.
Third, you must set properly the HTTP headers (strongly reccomended to read about it) so HTTP clients will be able to "understand" your application output, and render it in the browser.
Once you have managed this, would be time to implement the frontend (javascript, css, etc).

Writing CGI apps is a lot easier than GUI apps, because as it only writes plain text to console, you are not binded (not always) to external libraries, unless you choice to have more features as Sql databases, image processing, digitally signing, file access, etc.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Porting Freebasic fltk-c application to web based

Post by D.J.Peters »

Currently I learn HTML5, with cascade style sheets (css) you can build your own GUI
but if your app should work on tablets, smartphones and desktop PC browsers like safari, firefox, chrome, opera ...
(including touch to mouse ...) it's too much work the solution is a GUI framework give "jquery ui" a try

https://jqueryui.com
https://learn.jquery.com/

By the way yesterday i learned how to run other Javascript threads in the background with webWorkers()
that will run your GUI in the main thread of the browser smooth and a heavy task works parallel.

Joshy
dbickin
Posts: 59
Joined: Aug 03, 2005 16:40

Re: Porting Freebasic fltk-c application to web based

Post by dbickin »

@Julcar
First of all, you won't need any fltk-c library,
Thanks. The role of the GUI is to aide in placement of information and reading writing data to those places. Sounds like that is all manually done in html. At this point, I have only ever written html to dump info out, but not allowed the user to change the info and read the changes back. I am thinking that is html form stuff??

Actually I remember a decade or so at a linux user group, someone demoed how to let the user interact with the data, and it was so foreign to the how gui's work, that I just stared at it in disbelief. If I remember correctly, you had to manually costruct a table. Let the user change the values, then read ALL the data back again, and try to figure out what if anything had actually been changed to send it to the database.

Doable, but worth it? Right now I have a working solution, just every now and then I don't have that usb stick with me, or I just have my phone with me and would like to see my data.

@Joshy
it's too much work the solution is a GUI framework give "jquery ui" a try
Yeah, given my needs, the learning curve, it feels like "too much work."
jquery ui looks interesting, but the list of widgets doesn't seem to include a basic edit box or a grid to make a table. I guess you are expected to do that with the underlying html form stuff. I guess that, but didn't see it, so I guess that is something I am supposed to just know.

I guess I need to start from the beginning and take an html course. Any9ne have a link to a good one for me to start?

David
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Porting Freebasic fltk-c application to web based

Post by D.J.Peters »

dbickin wrote:jquery ui looks interesting, but the list of widgets doesn't seem to include a basic edit box or a grid to make a table.
web apps are a bit different :-)
All the primary text input like a edit box (single or multiline) or tables are a part of HTML !
The browser must understand the HTML tags for input and managed the interface to the user. You know what i mean ?
like this:

Code: Select all

<label for="name">Text Input:</label>
<input type="text" name="name" id="name" value="">
to make such things as a part of your GUI you put it in a HTML <div> tag and use a class name of your framework :-)

Code: Select all

<div class="ui-theme-of-your-framework">
  <label for="name">Text Input:</label>
  <input type="text" name="name" id="name" value="">
</div>
The w3 school is a really complete collection to learn modern WEB stuff.
HTML JAVASCRIPT CSS JQUERY ...

https://www.w3schools.com/tags/default.asp

happy learning old and new stuff :-)

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Porting Freebasic fltk-c application to web based

Post by D.J.Peters »

Or with other words:

Touch, Mouse, Keyboard or Joystick input are handled by the OS and are sended as Messages to the involved window of your app.

The Window (the parent container) of your browser app are a global var in the Javascript namespace.

pseudo code title = 'hello' is the same as window.title = 'hello'

Joshy
Post Reply