Context
I've been using Clojure for 4+ years. I recently setup Ring + Compojure, and have a good understanding of how they work. I also have a deep understanding of SVG.
Now, I'm aware of things like ClojureScriptOne, the Google Closure Library, and various online demos setting up Clojure + JQuery + WebSocket.
Question:
Can anyone provide a minimal demo for setting up:
* WebSocket in ClojureScript with the google Closure Library?
* Perferably with something involving a basic 2 person chat.
Now, I've looked into the Google Closure book. Unfortunately, when the book was released, it focused mainly on pull mechanisms (AJAX), and its only suggestion for push based mechanism was a long-living ajax session (via things like Comet). Apparently WebSockets were not mature or something at the time.
Thanks!
There's such an example for Aleph
The only thing you need to do wrt Closure's WebSocket object, is change the constructor for the wrapped socket to whatever Firefox's websocket is for Firefox (can't remember what it is, but it's not WebSocket), or at least that's what you used to have to do, but it works with Chrome anyway. Websockets work with Chrome, Firefox, Opera but not IE but you can use a lib that fixes things to use Flash if IE is that important
Have a look at httpkit websocket support
Related
It's something totally new for me, and since it seems to be something trivial, I can't find any response with our beloved friend ggle...
My question is : I have to create a webapp that can work if the client have nothing on his computer but a browser. My question is : is it possible to include to my project an external library (here I want to use PCL (Point Cloud library), a C++ library), and make it works even if the client have nothing installed? If I use QtWebKit for example, will I be able to create this kind of webapp?
Thanks a lot, and sorry for the (maybe) stupid question, I never did web dev before, it's my first time. ...
Have a nice day!
Wow, that question is as broad as the day is long, but here goes (you don't give too much about your background so I apologise if I am going too basic).
A web browser is just a piece of software that knows how to process HTML, CSS and Javascript passed over HTTP from a TCP socket.
So, on a most basic level, to get something to work in a browser all you need is to write a program that listens on a TCP socket and passes headers and HTML in the body of the response as per the HTTP protocol.
So, leaving aside the socket part, your method may look something like this:
std::cout << "<h1>Hello, world!</h1>" << std::endl;
In fact, the vast majority of the original dynamic web sites worked just like this: they were just C programs that just happened to produce HTML as output in the old days (cgi-bin).
The main issue with this approach is it's very tedious and time consuming to write code to that level of detail to generate HTML, especially when you factor in CSS and JavaScript.
This is one of the key reasons that most web applications these days are implemented in Java, .Net, Ruby, PHP etc as there is a wealth of fully-featured, stable and mature frameworks for web development that take the grunt work out of creating dynamic web sites (and C/C++ is much rarer).
However there are a couple of good frameworks out there for C++ if that is definitely the language you want to use.
Wikipedia has a limited section on C++ frameworks but it covers the 2 I would suggest investigating (CppCMS and Wt):
https://en.wikipedia.org/wiki/Comparison_of_web_frameworks#C.2B.2B
Of these, I've only had direct experience of CppCMS but I can recommend it - it's approach is idiomatic C++ (to my eyes at least, but I must confess I am more often a Java web developer than C++)
Also, there is quite a useful if slightly dogmatic SO discussion on this thread that may be relevant:
How popular is C++ for making websites/web applications?
I'm currently using Django served on Apache (mod_wsgi) for developing my apps. One of my favorite things is to 'fake' async requests with JavaScript's setInterval() function and AJAX to retrieve new data from database. For example:
// javascript
function someFunction() {
// do some stuff
setInterval(function() { fetchNewStuff() }, 1000); // run fetchNewStuff() every second
}
function fetchNewStuff() {
Dajaxice.main.fetch_new_stuff(fetch_new_stuff_callback, {'id':$(this).attr('user_id')});
}
function fetch_new_stuff_callback(data){
// append new stuff to my table, list or whatever in HTML page
}
As far as I am aware, this is perfectly fine for my needs. However, as my apps are growing bigger and more complex, this will eventually become too much hassle for both, my server and my clients, no matter how much I try to minimize transported data. Also, I cannot settle with the thing that in today's world I'm still 'faking' this :) So, I'd like to find some 'real' solution with push capabilities for my current and future projects.
I did try to google my problem and I have found many interesting stuff (Tornado, Nginx, Node.js, Twisted, etc.) but most of tutorials/articles/blogs are at least 6 months old and I believe that many things changed in that time. So far, I have tried to test Tornado and it was successful test, but I had some problems with setting it up on my production server. I also tried Node.js which is extremely simple since I know JavaScript very good, but then again, I'm not sure if it is a good solution.
My question here is - what would be the best thing (server, platform, framework, whatever) to implement in my current and future apps depending on this conditions:
easy to use (e.g. Node.js could fit in here)
eliminate 3rd party stuff as much as possible (some out-of-the-box solution, e.g. Django+Websockets and that's it [this was really just a silly example])
good documentation in use with Django (it would be perfect to have some real examples with my new technology and Django since I'm pretty much n00b for web servers and related stuff)
has a good perspective and future (I'm really looking to learn something which I will use a lot and which I wouldn't have to re-configure very often)
Thank you for your thoughts and any kind of help about this (links to some good, recently updated readings are more than welcome :)
You should have a look at django-socketio project, a Django app providing the features required to use websockets with Django via Socket.IO.
It uses gevent library along with socket.io.
EDIT 01
Sounds like web sockets is what I want.
Technical Background:
I am familiar Clojure + ring + composure.
I am starting to learn ClojureScript. (Have lein-cljsbuild setup; have also spent time installing ClojureScript "manually" just to see how it works.) Have the basic (alert (greeting "ClojureScript")) demo working.
What I want to create:
I want to create a basic two person Notepad (i.e. Instant Messenger, or two-person IRC channel). I want there to be a Clojure Server. When a client connects it shows it a text bok; the user types in some words, the clojure updates to the other user.
Question
I need some help getting started on this. Google Closure is a big library, I would like to understand things like:
(1) how do I setup a basic connection to get my cljs code and my clj code to send each other data
(2) once my cljs code received new data, how do I get it do update the DOM?
I think these are the two main things -- and if I had this, it would provide a framework for understanding the rest of clojurescript.
Thanks!
I wrote an example app that does this using clojurescript, ring, and websockets via a Webbit server:
https://github.com/aiba/clojurescript-chat-example
Hope this helps!
You (I) probably want WebSockets.
More to be updated (if I produce actual working code.)
Lots of languages have microframeworks for writing very tiny websites or web services, such as Flask for Python, or Sinatra for Ruby. On Squeak, there doesn't seem to be any equivalent; Iliad, Seaside, and AIDA are all very heavy for just having a little service. What's the preferred way to accomplish this? Directly injecting a hanlder into Comanche or Swazoo?
"In this particular case, I literally have three URLs that need to do stuff via HTTP POST; that's it."
For really simple cases, you can just register with (or subclass) Kom's HttpService like so (from the class comment, see for more info/options):
(HttpService on: 8080 named: 'Example Http Service')
onRequestDo: [ :httpRequest | SomeGlobal processRequest: httpRequest ];
start
You can also use teapot. Teapot is micro web framework on top of the Zinc HTTP components, that focuses on simplicity and ease of use. It's under 500 lines of code, not counting the tests.
Teapot on
GET: '/hi' -> 'Bonjour!';
GET: '/hi/<user>' -> [:req | 'Hello ', (req at: #user)];
GET: '/say/hi/*' -> (Send message: #greet: to: greeter);
start.
(ZnEasy get: 'http://localhost:1701/hi/user1') entity string. "Hello user1"
There are available mustache templates, output transformers, before filters. The framework is well documented.
I would like to share what I think is more up-to-date information (as of end of 2012).
Zinc Components
Currently in Pharo 1.4/2.0 the de-facto standard for HTTP client/server seems to be the Zinc HTTP Components. And the latest Seaside version (3.0) switched to Zinc as well.
You can of course use Zinc directly to implement web-services or serve web-pages.
Take a look particularly at classes ZnServer and search for classes like Zn*Delegate (like ZnDefaultServerDelegate or ZnStaticFileServerDelegate)
Seaside REST
Latest versions of Seaside include support for RESTful web-services. This can be used to implement web-services or serve web-pages. It's pretty straightforward.
For more information look at the "REST Services" chapter of the online Seaside book. This chapter centers about implementing web-services, but it works for web-pages as well.
Ratpack
I have also been told about Ratpack, a sinatra-like web-framework developed by Tim Felgentreff. There are two repositories. I think the github one is more recent. See here:
http://ss3.gemstone.com/ss/RatPack.html
https://github.com/timfel/ratpack
This information comes from a similar question I posted recently.
You can subclass a SwazooSite in Swazoo for such a micro website, but I think you will soon end needing more functionality, so starting directly on one of those three frameworks are better bet long-term.
That they are heavy is maybe just an impression and lack of better documentation of usage for such simple websites. Also, if you look at the framework as blackbox, which is complex internally but simple externally, then I'd say all Smalltalk web frameworks are quite simple comparing to other web frameworks.
Is there a relatively easy way to display the output of a C++ program on a webpage? And I don't mean manually, in other words, you see it on a webpage as it runs not as in I make a code tag and write it in myself.
EDIT: Just so everybody can get this clear I am going to post this up here. I am NOT trying to make a webpage in C++. Please excuse me if this sounds spiteful or anything but I am getting a lot of answers relating to that.
Step one, get yourself a server-side language. Be that PHP, ASP, Python, Ruby, whatever. Get it set up so you can serve it.
Step two, find your language's exec equivalent. Practically all of them have them. It'll let you run a command as if it were from the command line, usually with arguments and capture the output. Here's PHP's:
http://php.net/manual/en/function.exec.php
Of course, if you're passing user-input as arguments, sanitise!
I've just seen that you accepted Scott's answer. I usually wouldn't chase up a SO thread so persistently but I fear you're about to make a mistake that you'll come to regret down the line. Giving direct access to your program and its own built-in server is a terrible idea for two reasons:
You waste a day implementing this built-in server and then getting it to persist and testing it
More importantly, you've just opened up another attack vector into your server. When it comes to security, keep it simple.
You're far better having your C++ app running behind another (mature) server side language as all the work is done for you and it can filter the input to keep things safe.
You could write a CGI app in C++, or you could use an existing web server language to execute the command and send the output to the client.
You want to use Witty.
Wt (pronounced 'witty') is a C++
library for developing interactive web
applications.
The API is widget-centric and similar
to desktop GUI APIs. To the developer,
it offers complete abstraction of any
web-specific implementation details,
including event handling, graphics
support, graceful degradation (or
progressive enhancement), and pretty
URLs.
Unlike many page-based frameworks, Wt
was designed for creating stateful
applications that are at the same time
highly interactive (leveraging
techinques such as AJAX to their
fullest) and accessible (supporting
plain HTML browsers), using automatic
graceful degradation or progressive
enhancement.
The library comes with an application
server that acts as a stand-alone web
server or integrates through FastCGI
with other web servers.
I am not sure this is what you are looking for but you may want CGI You may want to look at this SO question, C++ may not be the best language for what you want to do.
based off the questions you posted Writing a web app like what you want is no simple task. What I would recommend is use some other library (this is one i found with a quick google) to get a web console on your server and give the user it is running under execute deny permissions on every folder except the folder you have your app installed.
This is still is a risky method if you don't set up the security correctly but it is the easiest solution without digging around too much on existing libraries to just have the application interactive.
EDIT --
The "Best" solution is learn AJAX and have your program post its own pages with it but like I said, it will not be easy.
It sounds like you want something like a telnet session embedded in a webpage. A quick google turns up many Java telnet apps, though I'm not qualified to evaluate which would be most ideal to embed in html.
You would set up the login script on the host machine to run your c++ app and the user would interact with it through the shell window. Note though that this will only work for pure command line apps. If you want to use a GUI app in this way, then you should look into remote desktop software or VNC.
It may be worth looking into Adobe's "Alchemy" project on Adobe Labs
This may help you with what you're trying to achieve.
:)
Are you looking for something like what codepad.org does? I believe they explain how they did it here.
There is a library called C++ Server Pages - Poco. I used it for one of my college project, its pretty good. There is also good documentation to get started with, u can find it here http://pocoproject.org/docs/