I have a Pyramid web application on which I would like to embed an iFrame displaying an instance of ParaViewWeb's visualizer so users can display VTU files remotely.
I have successfully done so while running the application on my own workstation by calling a subprocess from Python that executes ParaViewWeb's Quick Start method and returns the URL to JavaScript for iFrame generation.
http://www.paraview.org/ParaView3/Doc/Nightly/www/js-doc/index.html#!/guide/quick_start
However, in order to accommodate multiple users, ParaViewWeb's documentation indicates that
the server must provide a single entry point to establish a connection, as well as a mechanism to start a new visualization session on demand
for which it suggests using Apache as the front-end application and a python launcher to start the process for each session.
Conveniently, I have a "freshly installed Ubuntu Desktop 14.04 LTS" so I used the following guide to configure both the launcher and Apache:
http://www.paraview.org/ParaView3/Doc/Nightly/www/js-doc/index.html#!/guide/ubuntu_14_04
Ok so I'm pretty sure I am missing something major here, but once the launcher is started with /data/pvw/bin/start.sh... how do I then submit the request with information regarding what app to use (visualizer) and what data directory to load???
Update
I am able to launch a session such that a sessionURL with a unique ID is returned by first running
/data/pvw/bin$ ./start.sh
and then entering the following commands in the python interpreter
>>> import requests
>>> import json
>>> data = {"sessionManagerURL": "http://localhost:8080/paraview", "application": "visualizer"}
>>> data = json.dumps(data)
>>> r = requests.post("http://localhost:8080/paraview",data=data)
>>> r.json()['sessionURL']
u'ws://localhost/proxy?sessionId=e2970d68-42c8-11e5-a755-3c970e8061f9'
So now I have a websocket which should contain an instance of ParaViewWeb that I would like to access from the browser... typing the sessionURL as is into the browser does nothing and replacing 'ws' with 'http' opens a page with the following text:
AutobahnPython 0.6.0
I am not Web server, but a WebSocket endpoint. You can talk to me using the WebSocket protocol.
For more information, please visit my homepage.
I am new to both apache and websockets so I am reading up on the protocol on the homepage, but if someone has a quick answer about how to utilize this websocket to display ParaViewWeb to the user I would be very appreciative!!
Note: Command line argument -dr is unknown so omit it from all of the command line arguments given in the guide's launcher.json
Thanks in advance!
Related
I am new to nodejs. I have successfully installed it on my computer (and rebooted). I have created a hello_world.js inside My Documents directory (I'm on a windows xp computer):
console.log("hello world");
var my_http = require( 'http' );
var my_server = my_http.createServer( ... ) ;
...
I have successfully opened a windows command prompt, cd'd to the My Documents directory, executed the .js file, and received 'hello world' output. And I have navigated my browser to the running localhost port (for my experiment: http://localhost:1337/)
But I have 2 major questions based on this:
1 - where is 'http' ... I suppose it is a module(?), but I do not find such a directory within my nodejs installation directory.
2 - how does the http method, createServer, actually create a server? Does native javascript have such a method?
The node.js standard library is written in Javascript and C++, and C++ modules can be loaded in js code via process.binding. Specifically for http.createServer, it's a wrapper around _http_server.Server, which invokes net.Server, which uses the C++ TCP wrapper .
See here for more details.
To answer the second question, createServer just creates and populates the control object, the actual work is in listen, which first creates a handle and this is where C++ code is actually called for the first time.
1) http is a built-in node module. You can read up on the documentation for it here: https://nodejs.org/api/http.html. Node provides a lot of modules out of the box to assist w/ everyday operations (interacting w/ file systems, making HTTP requests, creating servers, working with paths, etc.)
2) Not sure what you mean by "native" JavaScript. JavaScript is just a language. I think you're really asking about the runtime environment. If you are using JavaScript in the browser, then no you can't start an HTTP server. But Node.js runs on the server, so in this environment it can do all sorts of stuff that you can't do w/ JavaScript in the browser, such as access the file system.
I have a socket.io implementation, and I'm trying to make it work across domains but it appears it can't. Here's my exact use case:
I have a node.js server running socket.io.
I have a JS / HTML5 game that I want to be able to host from anywhere, which has the client socket.io code and tries to connect to the server.
I have the same JS code running on mobile devices via SpiderMonkey (this is one of the main reasons I need to run this from any domain).
I find that I simply cannot connect to the socket unless I am serving the JS code from my node.js server to a browser. If I simply open the HTML file on my disk from my browser, for example, it will not work.
Server code:
io.on( "connection", function( socket )
{
this.socket = socket;
this.socket.on( "echo", function( str ){ this.socket.emit( "message", str ); }.bind( this ) );
}.bind( this ) );
Client code:
this.socket = io.connect( ip );
this.socket.on("message", function( str ) { console.log( str ); } );
And I can't even connect, I get my print out that it's trying to connect, but it never succeeds and then starts throwing ping errors. So, is this even possible? Or must I do it with long polling or something?
The error:
[Error] Failed to load resource: A server with the specified hostname could not be found. (socket.io, line 0)
EXTRA INFO:
This specifically will not work if I am trying to connect from an HTML file opened from disk using file:///. I am going to try across different machines on the same network...
Yes, Socket.IO works cross-domain just fine. The actual Socket.IO library can/should be loaded from the server hosting it.
EXTRA INFO: This specifically will not work if I am trying to connect from an HTML file opened from disk using file:///.
Don't do that. You run into all sorts of weird issues when loading files off disk vs. over HTTP.
Failed to load resource: A server with the specified hostname could not be found.
This usually implies that whatever hostname you're trying to connect to isn't resolvable, indicating a DNS problem or that you typoed your hostname. In any case, your code example doesn't show the relevant part where the problem may be. Use your browser's developer tools to first determine that everything is loading correctly. Then, verify the address of what you're trying to connect to.
I'm porting an ajaxed, mobile-optimized website to PhoneGap, but have been unsuccessful in getting any POST to the server. From what I've read, xhreq POSTS are supposed to be possible in PhoneGap.
The specifics: I'm targeting the Android platform using the latest Cordova 3.3.1-0.1.2, the latest Android SDK, and a Galaxy S3 updated by Verizon to Android 4.3. Connectivity is over wifi to my local server. In every attempt, the POST arrives at the server as a GET, with no post data (verified using tcpdump to inspect packets). The mobile-optimized web site works fine in the browser on the same phone, also over wifi.
I've isolated the fail case by creating a brand new Phonegap project, nothing more than:
$ cordova create Hello
$ cd Hello
$ cordova platform add android
Then in index.js, at the end of the onDeviceReady handler, adding a snippet I first tested in a simple browser page (domain substituted here):
// TEST POST CAPABILITY
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState==4 && (req.status==200 || req.status==0)) {
console.log("POST Response: " + req.responseText);
}
};
var t = new Date().getTime(); // Just to foil any caching
req.open("POST", "http://mydomain.com/services/rpc?t=" + t, true); // async
req.setRequestHeader('Content-type','application/text; charset=utf-8');
var postContent = JSON.stringify({id:t, method:"misc.log", params:[{log:"POST Test"}]});
req.send(postContent);
And then run on the phone with:
$ cordova run android
It fails like the fuller app, arriving at the server as a GET with no post data. I verified a couple of configuration item defaults to make sure they were as required:
In config.xml:
<access origin="*" />
In AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
Any ideas as to what might be going wrong, or other things to look in to?
Thanks.
Your content type should be set to
"application/json".
JSON.stringify() creates JSON content.
Next, can you tell us how your server process is determining the request type. Can you post the relevant code?
I would start by adjusting the content type value. See if that makes a difference.
Hope that helps.
The problem was an ip forwarding one, just not the one I'd originally suspected (forwarding to & from port 80 to my local server on port 8080, which I've used for years as a convenience to allow not having to add :8080 into the browser url all the time).
It was this:
In the MX records for "mydomain.com", I had www.mydomain.com pointing to my server's IP address, but the root mydomain.com (the host address I was using in the url to XMLHttpRequest), redirecting to www.mydomain.com.
This worked in a normal browser session, as if you type in mydomain.com, it just goes to www.mydomain.com, then runs from there - and it would use all relative paths in the xhreq's.
In PhoneGap, however, which requires the full path be specified, the POSTs were not making it through the redirect. It was also causing sluggish image loading behavior and some bizarre communication hangups after many loads - I just hadn't realized the problem had the same root cause (rather I was getting worried about WebView performance).
The great news is that POST is working fine now, and the WebView appears to be plenty speedy for my needs.
To summarize the solution: make sure that the subdomain (or lack thereof) in fully qualified urls passed to XMLHttpRequest (as required in PhoneGap) are mapped to an ip address (A record), and not redirected, in the MX records for your domain.
I am playing with an application cache and having problems with the swapCache function.
I have created the world's simplest cache manifest file:
CACHE MANIFEST
# Timestamp: 2013-03-01 11:28:49
CACHE:
media/myImage.png
NETWORK:
*
Running the application for the 1st time gives me this in the console:
Creating Application Cache with manifest http://blah_blah/offline.appcache
Application Cache Checking event
Application Cache Downloading event
Application Cache Progress event (0 of 1) http://blah_blah/media/myImage.png
Application Cache Progress event (1 of 1)
Application Cache Cached event
All well so far. Then I swap out the image and change the timestamp in the manifest file and get the following:
Adding master entry to Application Cache with manifest http://blah_blah/offline.appcache
Application Cache Downloading event
Application Cache Progress event (0 of 2) http://blah_blah/media/myImage.png
Application Cache Progress event (1 of 2) http://blah_blah/Widget/?invoke=myWidgetFunctionName
Application Cache Progress event (2 of 2)
Application Cache UpdateReady event
At which point the applicationCache.swapCache() function is called giving me a DOM exception 11 error.
MIME types all correctly configured on the webserver.
Anyone got any ideas / can point me in the right direction?
(I have read all the commonly linked appcache stuff online and can't see what am I doing wrong)
Thanks!
EDIT:
As I mentioned in the comments below, setting the expires headers on my web server for *.appcache files to expire immediately seems to have it working although I am still getting the DOM exception error(!?). I found the following blog entry which may help:
Possible Fix for Offline App Cache INVALIDSTATEERR
...but I have no idea how to set the MIME types client side. My google-Fu skillz have deserted me. Anyone?
I had the same issue. For a while I just disabled the cache if the browser was not chrome, but then I decided to try again, setting the mime-type as suggested. Firefox no longer throws an exception when I call swapCache(), and the whole refreshing process now works as expected. The mime-type has to be set server-side since the request isn't initiated from your web page, but the browser, so you have no control over how it reads the response. You have a couple options here. If you are using apache or IIS, you can do as koko suggested. If you are using a framework that handles routing for you and you configure the mapping of URLs to responses, such as rails or a python wsgi server, then you can typically set the content type manually. Here is my snippet of what I am using in my Python app using Bottle.py (WSGI based):
# BEFORE
#bottle.route(r"/<path:re:.+\.(manifest|appcache)>", auth=False)
def serve_cache_manifest(path):
return bottle.static_file(path, SITE_DIR)
# AFTER
#bottle.route(r"/<path:re:.+\.(manifest|appcache)>", auth=False)
def serve_cache_manifest(path):
return bottle.static_file(path, SITE_DIR, mimetype='text/cache-manifest')
Bottle comes with a utility function that handles returning static files that I am using. It has an optional parameter to set the mime-type.
tl;dr If you can't add the mime-type to your server configuration, you can almost always set it in your server side code (if you have
any).
I would suggest trying to comment out the catchall NETWORK whitelist.
NETWORK:
# *
The * would seem to require network access for all file, according to
https://developer.mozilla.org/en-US/docs/HTML/Using_the_application_cache
I commented out all NETWORK entries for now for a simple web application of mine and it works well.
using the answer of my previous question and another post I tried to implement facebook-chat from a browser. Here is what I did:
on an ubuntu virtual machine, I have python 2.6.5, python-twisted-conch 1:10.0.0-2, python-twisted-names 10.0.0-1, python-twisted-web 10.0.0-1 and python-twisted-words 10.0.0-2 already installed. I did not install jabberd2 server, I assumed facebook server is the Jabber/XMPP server in my case. Also I did not install pyopenssl.
downloaded and untared punjab from here
run it using the following command
user#ubunto: sudo twistd punjab
sometimes it tells that the process is already running under PID xxx but most times the reply was
Removing stale pidfile /home/user/twistd.pid
Does this mean that punjab is running?
In the punjab.tac file, according to this post I change the root.putChild line to
root.putChild('bosh', b)
On the other hand, I have an apache server running on the host computer (windows xp) to host my webpage that uses Strophe. In the apache config file httpd.conf, I proxy the BOSH requests to punjab at port 5280 using:
<IfModule proxy_http_module>
ProxyRequests Off
ProxyPass /bosh http://ubunto_ipAddress:5280/bosh
ProxyPassReverse /bosh http://ubunto_ipAddress:5280/bosh
</IfModule>
Note that the host and the virtual machine are bridged, so both get their IP address from the router and each one can ping the other. I also didn't install a jabber/xmpp server, or
For testing, I use the basic example of strophe as my webpage basic.html and basic.js with JID: FB_username#chat.facebook.com & password: FB_password.
I get the following:
Strophe is connecting.
SENT: <body rid='1709425072' xmlns='http://jabber.org/protocol/httpbind' to='chat.facebook.com' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
Strophe is disconnecting.
Is there anything wrong or missing? Please help since I am not finding real documentation other than some posts concerning this issue. Thanks
Sabah
I'm not certain this is what you're trying to do, but if you're trying to have a webpage independently connect to Facebook Chat via JS, it's not going to work due to Cross Site Scripting protections. You can only use Strophe to connect to the same server that issued the webpage Strophe is working on. You'll have to connect back to your server first and use that as an inbetween; or use iframes to embed facebook chat in your webpage.
(For the record, I know nothing about Python, but it looks like your problem is with the JS :) )