I'm using autobahn 0.4.10 (https://github.com/oberstet/Autobahn) as a WebSocket server to send messages to a Google Chrome Extension. I am able to open and close connections using WebSocket(), but when I call autobahn.websocket.WebSocketServerProtocol.sendMessage() the message appears to be sent but isn't delivered until the connection is closed.
The api for WebSocketServerProtocol's sendMessage() (derived from WebSocketProtocol) can be found here: http://www.tavendo.de/autobahn/doc/python/websocketprotocol.html#autobahn.websocket.WebSocketProtocol
Has anyone experienced this problem before?
The code I have been on the client side is (js):
ws = new WebSocket('ws://localhost:4444');
ws.onmessage = function(event) {
console.log('hii');
}
And on the server (python)...
#json is a string object
def sendEvent(self, json):
print 'to', self.peerstr
self.sendMessage(json, sync=True)
Both Autobahn and my version of Chrome (17.0.963.46) appear (from what I've gotten out of the headers and docs) to use version 13 of the WebSocket draft protocol.
Turns out this was a threading problem with some threads block the twisted reactor.
See:
http://groups.google.com/group/autobahnws/browse_thread/thread/6bf0c43ec169efc3#
http://twistedmatrix.com/documents/current/core/howto/threading.html
Autobahn works with Chrome (tested up to v19 .. Canary).
Could you try the
https://github.com/oberstet/Autobahn/blob/master/demo/broadcast/broadcast_server.py
demo to see if you have a general issue?
If that runs, direct your extension to that demo server .. it'll send you 1 tick per sec.
You can also enable debug output by changing the factory line to code like this
https://github.com/oberstet/Autobahn/blob/master/demo/echo/echo_server_with_logging.py#L50
2 more notes:
you don't need the sync = True option (it's really an advanced option .. mostly used with the Autobahn WS testsuite)
you might wanna join http://groups.google.com/group/autobahnws .. get answers more quickly .. I discovered your Q only by accident here
Disclosure: I am author of Autobahn and work for Tavendo.
Related
I have the following script through which I am trying to connect to openfire using WebSocket built in Firefox.
index.js
console.log(window.WebSocket);
var exampleSocket = new WebSocket("ws://localhost:5222/")
but it shows me the following error on browser console.
Firefox can’t establish a connection to the server at
ws://localhost:5222/.
can anybody tell me what I am doing wrong or there any other better way of doing this. I am using the latest version of Firefox.
First of all, make sure you have installed Openfire WebSocket plugin in the Openfire. so first check it's availability in plugins available. and then write the code as follows.
var exampleSocket = new WebSocket("ws://localhost:7070/ws/",'xmpp')
XMPP is the protocol for openfire
in case you want to check for the error you have to do like this.
exampleSocket.onerror = function(data){
console.log(data);
}
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!
I've created a simple WebSocket server and am trying to connect to it with the following code:
function test(name) {
var ws = new WebSocket('ws://localhost:1234');
ws.onopen = function () {
ws.send('Hello from ' + name);
}
}
test('Edge');
This works fine from Chrome and IE11 on Windows10 but when I try from Edge, the onopen function isn't called, instead I eventually get the following error:
SCRIPT12029: WebSocket Error: Network Error 12029, A connection with the server could not be established
This is happening for version 12.10240 of Edge.
A similar problem was asked about here but the error message is different.
Things I tried:
IP - localhost, 127.0.0.1, the actual IP
Allow localhost loopback flag - both on and off
When trying to communicate with a different machine the problem does not occur.
Is this a defect in Edge or am I doing something wrong?
I had a similar problem, but it was when actually navigating to pages in the browser. I could use the phrase localhost and it worked fine, but I didn't work when I used my machine's name. I found this forum where they suggested that you run the following command in a administrator prompt:
CheckNetIsolation LoopbackExempt -a -n=Microsoft.MicrosoftEdge_8wekyb3d8bbwe
Worked for me. Thought you might be seeing some form of the same issue.
As the forum suggests, you can now also do this by opening Edge and navigating to "about:flags", then tick "Allow localhost loopback (this might put your device at risk)" under "Developer Settings". Should feel a little safer than pasting random stuff into your command prompt.
Edit: As tresf pointed out below, the loopback checkbox in the about:flags appears to have stopped working (as a fix), so you'll have use the CheckNetIsolation command, to make Edge exempt.
I created in my Lotus Domino server a new application which is totally empty. I then created an XPage, and in it I modified the onClientLoad event, adding this client javascript code: alert("Hola");. When I preview the XPage on the browser, I get an HTTP 500 internal server error. The error on the server's log is this one:
26/06/2013 12:54:27 HTTP JVM: SEVERE: CLFAD####E: Exception thrown
26/06/2013 12:54:27 HTTP JVM: SEVERE: CLFAD####E: Exception occurred servicing request for: /Pruebajs.nsf/prueba.xsp - HTTP Code: 500
26/06/2013 12:54:27 HTTP Web Server: Command Not Handled Exception [/Pruebajs.nsf/prueba.xsp]
If I preview the same XPage on the Notes Client, the javascript code is run successfully.
I then created a similar application in my local machine instead of in the server, and the javascript code is run successfully, both in the web browser and the Notes client.
So it looks like some kind of configuration issue in our Domino server (maybe authorizations?), but we do not know where to look.
Thanks everybody for your help. Naveen's advice proved very useful. After checking "Display XPage runtime error" on Designer (Application -> Properties -> Tab XPages), the error message was much more meaningful:
The generated page version 8.5 is not compatible with the server version 3.0, for the page /prueba.xsp.
The problem is that my Notes Client and Designer are a higher (8.5.3) version than the Domino Server (8.5). According to this note: http://www-10.lotus.com/ldd/ddwiki.nsf/dx/XPagesPageVersions.htm, the eventHandler syntax has been changed slightly, and this causes the XPage to be marked as version 8.5.1. This also explains why it works when the database is local!
I have tried the workaround suggested in the note (altering in the page source back the event handler syntax to the 8.5 form), and it works. Now I will try to convince people around here to upgrade the server.
Thanks,
Carlos
Hi I have a Web Application and a Console Application in my C# .Net solution. I am trying to call a ReverseService class in my Console Application from my Web Application. In the Console Application in the static void Main function I am running the following code:
var host = new WebSocketsHost<ReverseService>(new Uri("ws://localhost:4502/reverse"));
host.AddWebSocketsEndpoint();
host.Open();
Console.ReadLine();
I am trying to call this WebSocketEndpoint from my Web Application with the following Javascript code in Chrome 12.
if (window.WebSocket) {
//establishes websocket connection
websocket = new WebSocket('ws://localhost:4502/reverse');
websocket.onopen = function () {
$('body').append('Connected.');
$('#inputbox').keyup(function () {
websocket.send($('#inputbox').val());
});
};
websocket.onclose = function () {
$('body').append('Closed.');
}
websocket.onmessage = function (event) {
$('#outputbox').val(event.data);
};
}
The websocket.onclose function does in fact get called, but the websocket.onopen function never does. I've googled and looked on here but to no avail, any help would be greatly appreciated.
The error is almost certainly a mismatch between the protocol versions for your client and server. It looks like you are using the HTML5 labs prototype - if you are using the most recent version then your server is talking WebSockets hybi-09. Chrome implements a much older version of the protocol (I think its hixie-76 but I am not certain).
Your options are:
Use a WebSocket server that implements hixie-76
Use a different client implementation. For example, you could use the implementation that is provided with the HTML5 labs prototype. Its a Silverlight plugin with a JavaScript wrapper. You need to include a few scripts and use new WebSocketDraft instead of new WebSocket. You will also need to drop the clientaccesspolicy.xml file in your wwwroot - see the prototype readme file for more info. Have a look at some of the samples for more info.
Use a TCP packet sniffer to watch the protocol handshake.
Successful tests with two protocols :
hybi-00/hixie-76 : Firefox 5.0, Safari 5.1.1 use this old protocol with Sec-WebSocket-Key1/Key2...
There are several free server source codes in C#.
For example search WebSocket76English.zip. It works even with Safari on iPhone.
hybi-06 : Firefox 7.0, Chrome 14 are using the last protocol with Sec-WebSocket-Key.
The last .Net WebSocket prototype use that protocol.
If someone has a version of WebSocket prototype supporting the old protocol hybi-00, please let me know.
The last specification draft suggest that a server can support several protocols and tell about
the supported versions in field Sec-WebSocket-Version.