I was hoping to make a website that displays a google map with points based of information returned by a C++ function. I know you can use Java Server Pages to call java methods on the server with javascript. Would there be a way to connect C++ code on the server with javascript in order to produce the same result as java server pages?
Since JavaScript runs at a completely different environment which is separated from the webserver by a HTTP connection, your best bet is to fire a HTTP request to the server side on a specific URL which has the particular C++ code attached.
You can fire asynchronous HTTP requests in JavaScript using XMLHttpRequest, the core technique behind "Ajax". The w3schools provides a concise introduction to Ajax. To make it all less verbose and bloated, you may consider to grab the jQuery library which has under each an $.ajax function for this purpose.
That said, Java Server Pages is absolutely not to be compared with JavaScript. JSP is a Java based server side view technology which provides a template to write HTML/CSS/JS in and offers capabilities to control the page flow dynamically and interact with backend Java code using taglibs and expression language. It runs all on the server machine, produces a HTML page and sends it over HTTP to the client side. The C++/C#/NET counterpart of JSP is ASP.
Related
What I mean is basically for example PHP, PHP can be used both to output data onto the client/browser and to connect/query databases.
Would it then be both a client side and a server side programming language?
Or is it still a server-side language as it's main use is database querying
Javascript too, js can be used as a client side language which is what it is but it can also be used to establish a connection to a database, does that then make it both a server and client side programming language?
thanks.
PHP's technically a "client" of your MySQL server, but "client side" in web development refers to code that runs on your user's web browser. PHP is an exclusively server-side technology (barring oddities like PHP-GTK).
JavaScript is both client-side (in browser) and server-side (via Node).
What makes a programming language client-side (if we're talking about Web development) is that it's being executed in the Web browser.
JavaScript is both a client and server-side language because it can be used to develop client application in your browser (or even mobile apps using environments like Apache Cordova) and also as backend technology thanks to runtimes like NodeJS which is entirely executed in a server machine.
PHP is a server-side-only language(1), and the fact that PHP scripts can act as clients of other server environments or technologies doesn't mean that it's a client-side language.
The client-side term refers to another physical layer away from the server which usually has a graphical user interface.
(1) Actually it's true that PHP can be used to develop other kinds of application like desktop apps, BTW, its main usage is server-side Web development.
Javascript can be used as both front end and back end programming language. For example AngularJS is used for front end and NodeJS is used for backend. NodeJS runs on server and AngularJS runs on browser.
PHP is server side programming language. PHP runs on server, not in web browser. PHP can output data to browser but it actually runs on server. PHP is "Hypertext Preprocessor". PHP engine process PHP code and returns final HTML code.
Client/server-side is not some property of language, but merely a place where you use it in each specific case.
Even in web development while JavaScript dominates client-side domain for historical reasons, there's no technical reasons that would stop you from using any other language inside browser using scripting hosts on Window - look up PerlScript, for example - or implementing JS-based translator/interpreter/compiler.
I want to execute some javascript that will send a string of text to a c++/java console application running on the same machine as the web browser
What javascript should I execute? and how should I receive the string?
As far as I know, there are two ways to transmit data to somewhere else using JavaScript. The first is using an XMLHttpRequest, the second is using a WebSocket. In both cases, the JavaScript code will establish a connection to another program, which in this case you want to be your C++/Java program.
In the first case, if you want to communicate using an XMLHttpRequest (or other libraries that use this, such as jQuery's get or post), you'd need to make sure that your C++/Java application starts a small webserver. This way, the JavaScript code can establish a connection to it and send data. I'm sure there are C++/Java libraries which you can use for this, but even if you can't it should be fairly simple to get something to work with just plain socket code. The text-based HTTP protocol that you need for this is not that difficult.
In the second case, you'd need to make sure that a WebSocket server is started in your C++/Java application. Your JavaScript code then can connect to this server and just send its data. I'm not that familiar with the WebSocket protocol but I suspect that it's slightly less trivial, so using a library for this would be a good choice.
Hi I was wondering how one would go about setting up a delphi server that can interact with a javascript client. I am developing a game with this tool : www.scirra.com
It is called construct 2 and it uses javascript. It has a plugin to use socket.io and websockets so either one would be great.
So basicly I want to develop a delphi server that would receive messages from the one javascript client and broadcast it to the other javascript client. If the user wanted to host a game he would run the delphi application and then join the game and wait for other players to join.
To sum up;
(A) Is it possible to use websockets in delphi to communicate with javascript.
(B) if so would someone please make a simple demo.
Thanks for your time
There are some WebSocket client and server implementations available (see WebSocket server implementations for Delphi).
By design, client-side JavaScript (in the browser) can use the WebSocket protocol to communicate with the server. The Delphi WebSocket server implementations then can handle the requests and push data back to the client just like any other WebSocket server library. However, I do not know anything about the code quality or Delphi version compatibility of all these libraries so some additional research is required.
Regarding the Demo: most libraries surely include some demo HTML with JavaScript / WebSocket communication. Simply download it and open it in your favorite text editor ;)
p.s. as I can see socket.io not only supports WebSocket but also long polling so basically you can use any HTTP server library for Delphi to write the server side logic. See:
How can I update HTML pages dynamically with Indy HTTP server using jQuery and "Long Polling"?
How to: update HTML pages dynamically using jQuery and “Long Polling”
I have a web site showing some data. It is constructed of:
- A web app, showing data.(ASP.Net app, but I don't use server side features in showing data; It's pure HTML and JavaScript)
- A Service providing data in Json format.(WCF)
the client requests data and receives and shows them.
Now I want to change the process in order to works in push base strategy.
I googled and I found out that that Comet is a good choice, but I don't found practical samples in my case.
Some samples had client with php (server-side) and so on.
Now I want some hints on using comet in a way that client is pure JavaScript and HTML and server is WCF (server pushes Json to JavaScript )
look at nComet it is an asp.net implementation of comet, not sure if it is wcf yet, but i would have thought much of the code would be reusable.
Or better pokein
I have an application on my server that is called leaf.exe, that haves two arguments needed to run, they are: inputfile and outputfile, that will be like this example:
pnote.exe input.pnt output.txt
They are all on the same directory as my home page file(the executable and the input file). But I need that a JavaScript could run the application like that, then I want to know how could I do this.
I'm using just Apache, I don't have any language for web installed on it. My goal is to do a site using just JavaScript, without the help of anyother language than it, HTML and CSS.
You would need to make an Ajax request to the server - the server would then have a handler that would then invoke the executable with the appropriate parameters.
Without know which web server technology you are using, it's harder to give a more concrete answer (ex: ASP.NET, PHP, Ruby, etc).
EDIT: If you're talking about doing this without any kind of server side resources, then this is impossible, and for good reason. Think of the security exploits!
Any other way to this without using other languages that need to be installed on the server?
No, but you almost certainly already have languages on the server. If it's a Linux, BSD or OSX server you've got shell script; if it's a Windows server you've got JScript and VBScript via Windows Scripting Host (using a cscript.exe hashbang).
JavaScript is for Client Side of a web application, so you won't be able to directly use javaScript to access server side files. As mentioned by Tejs, you should use Ajax to make a call to server side and then use appropriate server side routine to do the task.
Even at client side, most browsers don't allow accessing of any resource( e.g files) by javaScript code.
For server side javascript in Apache you could use Sun ONE Active Server Pages, formerly known as Chili!Soft ASP. For an IIS server, javascript is plainly available as asp-language.
Look into Rhino and node.js. I dont know a lot about this, but thats a route you can use for serverside javascript.