SpiderBasic as server-side language?

Everything else that doesn't fall into one of the other categories.
Klaus
Posts: 3
Joined: Thu Sep 10, 2015 8:37 pm

SpiderBasic as server-side language?

Post by Klaus »

Are there any plans to develop a server-side variant of SpiderBasic?
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: SpiderBasic as server-side language?

Post by Fred »

For now the sever-side programs can be done with PureBasic, the big brother of SpiderBasic. v5.40 will feature CGI and FastCGI support, so it should fir the needs for a fast server-side program.
Klaus
Posts: 3
Joined: Thu Sep 10, 2015 8:37 pm

Re: SpiderBasic as server-side language?

Post by Klaus »

Thanks! That's great.
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: SpiderBasic as server-side language?

Post by tj1010 »

Good luck finding a HTTP web host that will allow long-polling or sockets and doesn't have scale-killer metering.

You don't have socket support in SB either.

I actually know how to do websockets in SB using escapes and callbacks but can't be bothered to spend days writing and testing it. I went with a PB client for my multiplayer game till I can sub out work in some app language because I have a job that eats time right now.
mahan
Posts: 19
Joined: Sun Nov 15, 2015 9:44 pm

Re: SpiderBasic as server-side language?

Post by mahan »

To get going with server programming together with SB I'd recommend Node.JS as a server platform:

Basic steps needed:
  1. Go to https://nodejs.org/en/
  2. Download Node.JS for your OS and Install (there are versions for every OS SB supports)
  3. Create an empty directory for your Node.JS project somewhere
  4. Go to the directory
  5. type "npm init" <press enter> and just accept all defaults (<press enter> some more)
  6. type "npm install express --save" <press enter>
  7. create a file called "main.js" with the code I provided below.
  8. create another directory called "sbclient" inside the Node.JS project directory (Node will serve static files, that is: your SB program, from here)
  9. create an empty file in this directory called "index.html"
  10. Open compiler options in SB and point your export settings "HTML filename" to the index.html file in the "sbclient" directory you just created.
  11. Make sure you check the checkbox called "Copy SpiderBasic libraries"
  12. Close the compiler options dialog with OK-button
  13. In SB menu use "compiler"->"export" (the "sbclient" library should now be populated with your project.)
  14. Go back to the Node.JS directory with terminal (OS X/Linux) or cmd.exe (Windows)
  15. Type "node main.js" <press enter>
  16. In your web browser write the address: "localhost:3000" <press enter>
  17. (If you want to stop the server (or restart it after making changes) Press CTRL+C)
If you did everything correctly you now have a (fully programmable and high performance) web server, serving your SB program.

It's very easy to extend the main.js with url-handlers so that you can use HTTPRequest from SB and get results from server side, but I'll leave that as an exercise to you. (Google some examples/tutorials from the Express JS web site)

Someone mentioned web hosting, and I'd recommend using one that explicitly supports Node.JS if you go this path. Then "Long running process" is no problem.

main.js

Code: Select all

var express = require('express')
var app = express()

app.use(express.static(__dirname + '/sbclient'));

var server = app.listen(3000, function() {
  a = server.address();
  console.log('App listening at http://%s:%s', a.address, a.port);
})
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: SpiderBasic as server-side language?

Post by Fred »

This is great info, thanks !
Post Reply