Jump to content

node, mysql and socket.io


Recommended Posts

  • Moderators
It has been announced for some time that the new and upcoming SMS release will have added support for databases (via node) and client/server connections (sockets).

 

This update has not happened yet so below is a snippet which may be of interest in the meantime.

 

Starting point is an example in pure js (server=node, client = html/js) which defines an application which features a central MySql database.

Every connected client gets the entries in the main table of the database listed and can add new entries.

New entries are pushed to all connected users in real time and the app lists the number of all connected users as well.

 

This example works straight out of the box.

 

 

To rewrite the client js code in Smart pascal a wrapper is necessary around the socket.io library

 

For this I used Christians ts2pas converter

The translation is not perfect but since only 2 functions are used here ('emit' and 'on'), the only parts necessary are

 



type
 
  JEmitter = class external
    function on(event: String; fn: procedure(data:variant)): JEmitter;
  end;
 
  JSocket = class external(JEmitter)
    function emit(event: String; args: array of Variant): JSocket;
  end;
 


 

It works for me to re-build this into a proper component (TSocket) as well

 



 

 

This all works quite well.

 

However some problems are :

 

Clientside all modern browsers work except Edge

 

Serverside stability depends on the server-environment.

Hosting node on localhost Win10 is not 100% stable (server scripts crashing, ports reportedly in use after recovery, node.js service needs to be stopped manually). Things like that

Allegedly professional node service providers like Heroku are more stable

.

Link to post
Share on other sites

I so want to post the code I have made for this, but I cannot without the board's backing.

But I will make some calls today and see if we at least can get the units/changes that are finished out.

 

We are low on manpower, and right now im the only one coding on the RTL.

But if people are ok with many small updates, and that we issue 1 by 1 unit as I finish them - then that's ok by me.

 

Hopefully that would help?

Link to post
Share on other sites
  • Moderators

I don't mind incremental upgrades if that's the way forward for now

 

Would be good if these increments were complemented with typical use case scenarios (examples) for new functionality, as part of the documentation

and whether or not it would impact existing code 

I'm sure some of us could help with that as well

Link to post
Share on other sites
  • 8 months later...

> I haven't tried anything like this before but...With a pro version of SMS is

> it be possible to write a server side app that talks to our websites mySQL

> database via node?Or do I need the full enterprise SMS package?

 

It is, I don't know what are the differences in new version of SMS but in existing, Enterprise basically offered RemObject/DataSnap support. If you work with mORMot or NodeJS as backend, pro version is good enough.

Link to post
Share on other sites
  • Moderators

the enterprise package gives support for RemObjects and DataSnap (http://smartmobilestudio.com/feature-matrix/)

Basically you can write your serverside app in Delphi (in a version which supports RemObjects and/or DataSnap)

 

Up till now I usually used serverside MySql with the server component written in php. These php server components can be very simple indeed if you only want to serve sql queries, a matter of 5 lines or less, with the client side just normal sms using xhttp.

 

The other way of doing it (i was waiting for the alpha) is to use node server-side. You can use sms to both code the node side of things and the client side.

 

Both ways don't require the enterprise package

Link to post
Share on other sites
  • Administrators

Alright, the current schedule sees this as a mid future feature which we will add once the more fundamental features and bugs are taken care of. We will then decide on the best possible database engine which will give the users the fastest and most stable access to their databases from the script. Please be patient, this is definitely on our road map, but one after another! ;)

Link to post
Share on other sites

I see that this is a wonderful product in the future.

Many old delphis guys will drop the enjoyment of programming again.

 

It would be worth thinking about the priority.

I also like to run Sinclair Spectrum emulators,

but for that I will never pay more for a smile.

The money users will come from the business sector.

 

Without an easy-to-use database manager

I'm sorry waiting for the pay button :(

 

I hate accounting programs just like you.

If I can only do graphic programs,

but unfortunately I can not save 'txt' or 'ini' files to the server... :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...