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”
Related
Using a browser, is it possible using client only technologies (like JS, HTML ...) to send data to another browser without going through the server that servers the HTML page?? I mean if both ends are already synchronized (one has open a port, and the other one sends the data), is it possible to do that?
With only javascript and HTML, the answer is clearly no : you can't establish a direct P2P connection.
There are solutions involving a plugin, for example java (in the case of java, the user has to relax security, usually through signing).
But note that with websockets you connect and exchange through a server but it's efficient enough for most uses (provided your users will accept not to use IE9-). WebSocket programming is easy enough those days (here's an example of a complete chat client/server, googling would give an example for your favorite language) so I really recommend not to try using a plugin.
HTTP requires a server. For personal projects you can try the web server plug-in for Firefox:
https://addons.mozilla.org/en-us/firefox/addon/pow-plain-old-webserver/
You can't do a direct client-to-client transaction with JS, HTML yet, but if you check red5 to uses Java frame work, it provides RTMP(Real Time Media Protocol) which for P2P connection.
There is a server I need to talk to that publishes a protocol over TCP/IP for querying data from a database and listening on a socket to receive notifications when data is updated. The sever guys provide a Java API which uses this TCP protocol. This means I could easily write a Swing App to talk to this server.
I would like a browser based solution. As the protocol is known to me, could I do this in JavaScript? My app will have to display the data in a table. I have heard of Web Sockets but I'm not sure if it will allow this two way communication. Is it feasible? Is there a better way that is cross platform and will work in most browsers? Should I be considering a Java Swing based solution that runs inside a browser?
EDIT: What about changing the code in my C++ server to add an additional interface that my Javascript code can communicate directly with it?
The WebSocket protocol differs from TCP/IP sockets. You will have to write something to link them together.
You can do this perfectly well in JavaScript: use Node.js. There's enough tutorials to be found on the subject. The best way to link it to your in-browser JS is through Socket.IO.
Create a Node.js server that connects to the api
Make the server talk to your web app
Use it :)
This will work cross-platform and cross-browser (Socket.IO can use/emulate websockets even on IE6(!!)). You'll have to run a server-app (the Node.js app) though.
My personal opinion is that if you want a web/browser based solution, you should use native technology, and not Java.
Hope this helps :)
I have a server that creates a websocket. I'm using HTML5, Javascript and JQuery on the client side.
My fellow-student who works on the project uses RFID technology to scan a tag. Then he needs to send me those data from his app via the socket.
Is that possible with his preferred language C++? And how does he need to do that?
There are some websocket implementations for C++ available. See http://en.wikipedia.org/wiki/Comparison_of_WebSocket_implementations Unfortunately I don't have experience with any of them.
When none of these libraries works out for you, I would not recommend that you create your own implementation of WebSocket. It's not a very simple protocol (I know what I am talking about - I wrote a websocket server in Java) and it only makes sense when the client is a web browser. When the client is able to use pure TCP/IP sockets, like a client written in C++, there is no reason to add WebSocket as another layer of indirection.
So you should rather implement an alternative network handler on your server which listens to a normal non-web socket. That would be a lot easier and also reduce protocol overhead and CPU load on client and server.
Sorry for the cryptic title, struggling to summarise my problem in a single line...
I wish to deploy an online, hosted website to serve a series of remote terminals which will be equipped with Chip & Pin payment card readers (aka pinpads). The pinpads are driven by some software on the PC within the terminal which is written by a 3rd party. The integration methods supported by this software are either text file based or socket based with a "request" and "response" workflow.
I have successfully carried out similar integrations in the past using client side VB Script to instantiate client side COM objects which communicate via socket connection with the local 3rd party software but this approach ties me to Windows and I would prefer to keep my options open.
My web server will be Ruby On Rails based and I intend to use HTML5 and CSS3 to provide a rich experience on the payment terminals and wondered if I can use web sockets for client side communications? From what I understand, this is not what they are designed for and so I think the answer is no.
So, what are my options? Can i use client side JavaScript to carry out socket communications or is this prevented by browser security measures? From the browser's perspective it would be communicating with a specific numbered port on "localhost"
If socket comms is not possible, can I use JavaScript to create client side text files to integrate that way?
Or am I stuck with VB script and local COM objects?
Any suggestions would be most welcome and please let me know if you need clarification on any aspect of my question.
Kind regards,
Craig.
I don't think you can write a text file with JavaScript. And you can't put arbitrary bytes on a socket either. I don't completely understand you scenario. It sounds like you have Ruby sunning on a server and JavaScript and this third party pinpad thing running on a client. And you need the two client entities to be able to talk to each other. Could you have the browser communicate with your Ruby server (using one of many web technologies) and then have your Ruby server relay the data back to the pinpad socket. Or is the pinpad only a local socket?
The only type of socket-based connection you are allowed to open on a standard web page that runs javascript is an HTTP socket. You'll have a lot more freedom to use sockets if you develop a browser plugin, which is written in javascript. Firefox, I know, supports sockets in extensions.
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsISocketProvider
We have a network camera. It has an HTTP server to provides the current image. There is also a Telnet interface for controlling the camera (i.e. trigger, focus, etc.). I would like to add an HTML page to the camera that would provide a simple interface (we already have client software we write). I can "GET" the image and display that, but I would also like to have controls that use the Telnet interface to control the camera. So a button might have JavaScript code behind it that connects to the camera via Telnet (logs in) and issues the command to trigger the camera.
I know that JavaScript/browsers support connecting to the same host via XMLHttpRequest. In this case I would be looking to open a socket on port 23 and send text. I also know that I can do this through Flash, Java, or some other technology, but I would prefer to use JavaScript only. If that is possible.
Thomaschaaf is correct, while HTML5 introduces websockets you'll find they still require special server support as they post HTTP style information upon opening the socket:
JS/HTML5 WebSocket: Connect without HTTP call
The best way, currently, to have true sockets is to either
use a flash or Java component on the webpage that does the actual socket work.
use a proxy server with websockets that can handle the additional protocol overhead of websockets and connect to the real tcp/ip port with plain sockets.
The jsterm example Matt linked does the latter, and if your webcans are behind a firewall it will not work in your situation without also implementing another server.
There are libraries that implement the first method, two are linked here for convenience, many others can be found using a search engine:
http://stephengware.com/proj/javasocketbridge/ (Java)
http://matthaynes.net/blog/2008/07/17/socketbridge-flash-javascript-socket-bridge/ (Flash)
jsTerm is an HTML5 implementation of a Telnet client.
You'll need a browser that supports HTML5 WebSockets. WebSockets is the only method of doing non-HTTP requests with pure JavaScript.
Currently there is no way to do socket connections with JavaScript only.
But what you are searching for is a socket connection ;)
https://developer.mozilla.org/en/XML_Extras
If I interpret the question liberally as "is there a remote connectivity library for Javascript", then the answer is yes (quoting from https://xtermjs.org/):
A web based SSH2 client using xterm.js, socket.io, and ssh2: https://github.com/billchurch/WebSSH2
HTML5 Based SSHv2 Web Client with E2E encryption utilising xterm.js, SJCL & websockets: https://github.com/stuicey/SSHy
I've tried WebSSH2 with node.js briefly, it worked for me - I managed to connect to a Linux-based server with it.
(I know this probably doesn't help the OP but this is a 7-year old question anyway. Maybe it helps others who are needing an answer to a similar problem.)