How do I interface with websockets as a client using Immutant? - clojure

I'm building a Clojure app that needs to interface with Slack's real time API, and that requires a connection to a Websocket.
I am aware this is possible with gniazdo, but this pulls in Jetty, and I believe that Immutant has its own Websocket abstraction.
I've also tried using clj-http, but it does not recognise the wss:// protocol, which is the URL returned from the Slack API.
Would greatly appreciate it if I were pointed in the right direction. Thanks!

Immutant uses Undertow as it's web server, which provides the wss protocol support you seek. Sadly, looking through the Immutant clojure wrapper code I don't see any part touching this functionality, so you will have to use Clojure's Java interop facilities.
The relevant source seems to be implemented here.

Related

Clojure + stomp + websockets

I have followed a couple of tutorials about interactive/real-time applications using STOMP over WebSockets with the Spring framework using the messaging layer.
Example in Spring
I would like to implement the same functionality in clojure. Has anybody experience in implementing a similar application? I have been looking for documentation/examples about using these technologies, but there is nothing like the examples in clojure.
That it makes sense? Is it necessary to have an external message broker to connect the backend app and the browser clients?
I have some experience using a broker to pass messages along. However, I think it's still best to write your own http frontend for the browser to talk to. That frontend in turn can post messages to a broker (using Stomp or any other protocol). That way, you have more control and you're not tied to a message broker. For instance you can have the frontend do more than just websockets, like serve static files, or a regular HTTP interface.
But that's up to you, if the broker supports websockets, you can use that too (see for instance ActiveMQ). My advice is: try the simplest possible way first :-).
Take a look at Http-kit for a good Clojure webserver. It also has good websocket support.

Socket.io for other platform than node.js

I'm looking for a library that work exactly like socket.io(node.js) but I need it in other platform, c++ or maybe python.
This is about server application for website. My app work with node.js but I need to change it for C++/python or something other.
socket.io is great because it choose technology automatically to connect with server - depend which browser/hardware you use.
Any ideas?
For Python, you could look into >> Websockets with python <<
Can I use Socket.IO with Django?
Django is a web-framework that uses Python language.
There is a Socket.IO implementation for python via TornadIO2, which is to be used with the Tornado async web server. I have used this when it was TornadIO 1.0
Go has one that I use, but its only compatible to Socket.IO 0.6.x: go-socket.io
And just look at the socket.io Wiki for other links:
https://github.com/learnboost/socket.io/wiki
The protocol definition for socket.io is available here
https://github.com/LearnBoost/socket.io-spec
I have been part of a couple of project where we decided to actually implement our own client for various reasons. It is not that hard especially since you only have to support on transport (xhr-polling is the easiest imho).
And also maybe a possibility to give back to the community....

Calling c/c++ library from webserver

I am pretty new to web programming.I am developing a HTML5 based user interface which is supposed to use a middle ware written in C/C++.How can I do this?
I do not want to use any browser specific feature/library to communicate with the middle ware. Can we do the same at the server side and then send back the information to the browser? If so how can I achieve this communication with the middle ware at the server side?
Thanks in advance for the reply.
Note : I am planning to use Tomcat as the server in loop back.
As suggested above, you could use CGI (e.g., perl scripts) as a middle-man between the Tomcat server and your C++ middleware. What I also think might work well, and am planning on using myself in the near future, is to use boost::asio, and take the example HTTP server and modify it to use your middleware. You could then communicate between the Tomcat server and the C++ server using AJAX with JSON.
There is also something called pion server http://www.pion.org/projects/pion-network-library
It allows you to write the entire server in your own C++, with most of the common tasks abstracted away.
The Wt "web toolkit" library (pronounced "witty") may be of interest. Essentially all web-aspects are taken care of this, so absolutely no middleware. Here is an intro, quoting from the website:
The API is widget-centric and uses well-tested patterns of desktop GUI
development tailored to the web. To the developer, it offers
abstraction of web-specific implementation details, including
client-server protocols, event handling, graphics support, graceful
degradation (or progressive enhancement), and URL handling.
Unlike many page-based frameworks, Wt was designed for creating
stateful applications that are at the same time highly interactive
(leveraging techinques such as WebSockets and Ajax to their fullest)
and accessible (supporting plain HTML browsers), using automatic
graceful degradation or progressive enhancement. Things that are
natural and simple with Wt would require an impractical amount of
effort otherwise: switching widgets using animations, while being
perfectly indexed by search robots with clean URLs, or having a
persistent chat widget open throughout, that even works in legacy
browsers like Microsoft Internet Explorer 6.
It can run with its own web server (based on a Boost component) or be linked against standard web server libraries.
I wrote a short blog post about how to integrate it with another C++ component I wrote (RInside, which permits to embed R inside C++ apps) and by joining the two, I had a simple 'webapp' exporting R functionality to the web.
You can further enhance it via Javascript but that is something I have not looked into in any detail.

clojure library for SPNEGO/Kerberos-http authentication

I understand this is a long shot but, would there happen to be a clojure library for responding to kerberos over http (aka spnego) requests?
I'm currently looking into using spring-security framework for this but thought i'd ask about a more clojure friendly approach just in case.
There's nothing special involved to integrate a clojure app with Spring Security. However, you are bound by its implementation as a servlet filter, so you cannot easily use it under a generic http library. Under a j2ee container, it is a good choice.

What is a good platform for devoloping web services in C++?

We're looking at developing a Web Service to function as a basis for a browser display/gui for a networked security prototype written in C++. My experience with web services has been limited to Java. I prefer Web Services in Java because it's on the "beaten path".
One sure was to do this would be to simply code a Java client which invokes the web service, and call it as a command line with parameters from the C++ code.
It's not ideal, since generally speaking an API is preferable, but in this case it would work and be a pretty safe solution.
A resource which does handles web service development in C++ is called gSOAP, at this url: http://gsoap2.sourceforge.net
Any thought on which is a better approach? Has anyone used gSOAP, and if so, what did you think?
I'd done things with gSOAP, it's not awful. I'm increasingly opposed to the RPC model for web services, though; it forces you into a lot of connection and session state that adds complexity. A REST interface is simpler and more robust.
To me is Axis C++.
For RPC style, have a look at Thrift,
I found it quite better ( faster, clearer, a lot of languages implementations) than soap.
My colleague ended up using a combination of Axis2 / java (for the service) and gsoap for the client. He created the wsdl from the Java service by generating it from a C++ header (using c2wsdl (?) or something like that. He said it was better than using a Java interface because that generated two sets of wsdl, for seperate versions of soap.
Then he used wsdl2java to generate the webservice and a test web client. Once we got that working, he used gsoap to create the web client (in C++), and it worked fine.
thanks for all the answers! I ended using a combination of them.
I had very good experience with gsoap - very simple, performance is good.
If it is acceptable to run only on Windows, there is a brand-new API for that purpose: WWSAPI
Instead of calling the java client from the command line, you can create a java virtual machine inside your C app, instantiate the class and call any methods. This is what the java.exe app does and I think the source code is included in the jdk.
Depends on how low level you want to go. You might checkout yield.