Is it possible for a firefox addon to establish a websocket connections?
When I try:
var wsUri = "ws://echo.websocket.org/";
var ws = gBrowser.contentWindow.window.WebSocket ||
gBrowser.contentWindow.window.MozWebSocket;
var websocket = new ws(wsUri);
In the Error Console the message says
Error: Firefox can't establish a connection to the server at ws://echo.websocket.org/.
Currently, it seems the only option is to proxy your WebSocket messages through a PageWorker. There is an example of how to do this on this website:
http://austinhartzheim.me/blog/4/websockets-firefox-sdk-addons/
Related
If i don't have server details then who will establish or install the web socket connection? Can admin (who handle our host) establish connection and provide me the URL of websocket to use in android or angular code?
Is this necessary to write code in php?
I expect server admin install and configure web socket and provide to use in chat module.
Web admin(Ops) can help create the domain name but you have to write serverside code to handle websocket connection. You can use any programming language that supports websocket. for example,
nodejs - https://github.com/websockets/ws
java - https://docs.oracle.com/javaee/7/api/javax/websocket/package-summary.html
With java websocket you simply can define ServerEndpoint and deploy the war(web archive) to any host or cloud provider(Amazon cloud, google cloud etc),
#ServerEndpoint("/chat/{clientId}")
public class MyWebsocketServer {
#OnMessage
public String handleMessage(#PathParam("clientId") String clientId,
String message,
Session session) {
System.out.println("chat message: " + clientId + "/" +message);
return "hi how are you doing?";
}
}
Now, with javascript as a client your code to establish WebSocket connection would be:
var clientId = Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);
var webSocket = new WebSocket("ws://localhost:8080/my-app/chat/" + clientId);
localhost means I'm running both Server and Client in same host, in your case serving host might be www.mike-simons.com/chat while client running on phone
Example: https://github.com/duwamish-os/chat-server_websocket-java
I followed the tutorial on the official site of the django channels. Everything is fine. But now, how do I connect to the ongoing socket and push message to the group in the server side (i.e. via django) ?
In the tutorial, following line of code in the js opens up a WebSocket connection simply by calling the WebSocket constructor:
var chatSocket = new WebSocket('ws://' + window.location.host + '/ws/chat/' + roomName + '/');
And I want to connect to the same socket in the server side. I tried this:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('ws://127.0.0.1/ws/chat/2', 6379))
but I get error saying
socket.gaierror: [Errno -2] Name or service not known
I am a complete beginner in socket programming, and apologize if there is anything minor that I may have skipped.
Ratchet worked perfect until I updated my composer, after that it produce this error on chrome
WebSocket connection to 'wss://mysite.com/wss2/' failed: Error during WebSocket handshake: Unexpected response code: 302
on Mozilla
Firefox can’t establish a connection to the server at wss://mysite.com/wss2/.
httpd.conf
ProxyPass /wss2/ ws://myIP:8888/
socket.js
var conn = new ab.Session('wss://mysite.com/wss2/',
Does anyone know what might be the problem? thanks!
I am working on web application for client side which is user websocket connection to send/receive data.
Here is my problem.
If some parameter change on client side, I want to close my web socket connection and initiate new connection with new paramaeters.
I tried to close web socket connection bu using close(). But when I checked my browser console, websocket status is always 2.
Please help me to resolve this.
I am not completely sure of what problem you have, but if you set a handler for onclose, it will be triggered when you call close.
var ws = new WebSocket('wss://wss://echo.websocket.org');
ws.onclose=function(){
alert('The websocket just closed, readyState: ' + ws.readyState);
}
Demo: http://jsfiddle.net/6kh20bdy/
ReadyState 3 means closed: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Constants
Do you know what can I do to check if proxy in WebBrowser is working properly?
Well, if the proxy does not exist, you will have an error:
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8, "localhost", 8080);
HtmlPage page = webClient.getPage("http://htmlunit.sf.net");
System.out.println(page.asText());
org.apache.http.conn.HttpHostConnectException:
Connection to http://localhost:8080
refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:127)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147)
If the proxy misbehaves, you will have a different page than what you expected