Error when using ssl with websocket - javascript

I am using ssl communication with websocket.
so I added the secure communication in my javascript code like this "wss://myip"
when lunch a websocket communication from my page with https://myip
i get the following error.
failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR
I am using lighttpd server and chrome navigator on a linux machine.
could any one help me?thanks in advance

At present, this does not appear to be supported by lighttpd. The following link suggests using HAProxy as frontend to proxy the traffic to the websockets application:
Redirecting websocket traffic on port 80 with lighttpd
(actually without lighttpd)

Related

Connect to plain socket from JavaScript [duplicate]

I have a java client and I need to rewrite it in (client-side) javascript.
I open the java Socket like this:
Socket socket = new Socket("127.0.0.1", 5015);
So I tried to use websocket in javascript:
let socket = new WebSocket("http://127.0.0.1:5015");
but here I have a js error:
Uncaught DOMException: Failed to construct 'WebSocket':
The URL's scheme must be either 'ws' or 'wss'. 'http' is not allowed.
I tried also to use the 'ws' or 'wss' protocol but the server didn't want to handshake with such protocols.
Is there a way to make such socket connection in client-side javascript or it's definitely prohibited?
The answer is a little more complicated than "no you can't do it".
Javascript in a regular web page running in a web browser cannot open a plain socket. The fundamental reason is that it is a security risk for the user. So it is intentionally not allowed.
WebSockets are the secure way to do this. In conjunction with other browser security mechanisms, they limit what a web page is permitted to connect to.
However, that is not the end of the story. It is possible (at least in theory) for trusted code to send and receive TCP and UDP traffic. The problem is that the APIs for doing this are non-standard (e.g. browser specific). In some cases are themselves implemented as 3rd-party browser extensions.
So if you really wanted to pursue this for you application, you are going to have to distribute your code as a trusted browser plugin / extension AND deal with a range of browser portability issues.
It is worth noting that there was a W3C Working Group that was trying to standardize raw socket APIs, but they have officially abandoned their efforts. Their last working draft can be found at:
https://www.w3.org/TR/tcp-udp-sockets/
Finally, there is the problem that a trusted browser extension / plugin requires the user's consent to install. Getting informed consent for something like this is difficult, given the deep and subtle security issues associated with embedding this kind of functionality in the user's browser.
No, you can't make an arbitrary TCP connection from a web page in any browser.
Web Sockets are fundamentally different than TCP sockets... they're essentially unrelated. They're a thin layer on top of HTTP along with a client API which allows bidirectional communication between a Web Socket client and a server supporting Web Sockets.
There are proxy servers you can run that allow connecting through them to make TCP connections, but this of course is a server feature and not something you can do in-browser alone.
The opening handshake is intended to be compatible with HTTP-based
server-side software and intermediaries, so that a single port can be
used by both HTTP clients talking to that server and WebSocket
clients talking to that server. To this end, the WebSocket client's
handshake is an HTTP Upgrade request:
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
https://www.rfc-editor.org/rfc/rfc6455
WebSockets server must be able to handle HTTP requests!

SOP violation in paho mqtt

when I am trying to use Paho MQTT javacrript with Mosquito MQTT websockets, everything works as long as the web server that I am using to serve my page and Mosquito are in the same server (same origin). However, if I try to connect to a different Mosquito instance (cross domain), Firefox throws a security error.
Problem is that the Javascript client initiates a http connection to the Mosquito web socket server and it gets upgraded to ws:// as part of negotiation. Had the initial request itself been over ws:// , SOP would not have kicked in.
I tried to connect to the second server from http://mitsuruog.github.io/what-mqtt/ and it works fine without SOP error. So, I know that the server can support ws:// . How to get this done using the Paho implementation?
Is there any way to work around this?
The issue is that I was trying to initiate an un-secure (ws:// instrad of wss://) while the page was itself loaded over https:// . This results in a mixed content error that is not explicitly reported by Firefox. Chrome prints a better warning and allows to temporarily bypass it as well.

websocket connection error in https website

I want to implement basic chat application in php using the websocket and its working fine in my local server and http website but its not working for the https website. I have implemented the chat from this Simple Chat using php
In javascript i was connecting to websocket like this
var wsUri = "ws://mydomain:9000/server.php";
websocket = new WebSocket(wsUri);
I have used for my https website wss:// instead of ws://
And its giving the error in console
WebSocket connection to 'wss://mydomain:9000/server.php' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
And if i observe the terminal its giving the error like "socket_getpeername() : unable to retrieve the peer name[107] Transport endpoint is not connected"
I googled for the same issue but i didn't get any proper solution. Please suggest me how can i set the socket options for ssl.
In this same case we get an error display like below error.
"failed: Error in connection establishment:
net::ERR_SSL_PROTOCOL_ERROR".
In server page we use socket extensions functions, starts with soket_.
If any know about how to connect ssl with this socket extensions functions.Any clarification my question please post your command.

how to connect with non secure websocket on https?

I am using a websocket to get market data it was working fine but when i install SSL on my dedicated server my websockets stopped working i found that i am calling a non secure websocket on secure place means i was trying to connect with websocket using WS after that i tried to connect with server using WSS but its giving error that connection refused. is there any way to call non secure websocket on https something like in iframe or please tell me the reason why its refusing WSS connection??
Thanks in advance !!!

Does XMPP server MongooseIM work with BOSH or WebSocket?

I am using MongooseIM as my XMPP server, and this server typically use TCP as transport. This server works fine with my iOS client. But when I want to create the same service in web app, I found out that it does not work with any kind of javascript XMPP framework.
Because with browser, we cannot use TCP as transport. Instead, the alternatives are WebSocket and BOSH. When I use WebSocket with MongooseIM, it shows hand shake failed . While with BOSH, it shows 403 error. So does MongooseIM really work with WebSocket or BOSH?
And also, with TCP as my transport, the connection url is 'example.org', why it would be 'example.org/http-bind' with BOSH? Why is there the difference between 2 transport?
Pure XMPP TCP connection, BOSH and Websockets are quite different protocols. Both BOSH and Websockets use separate suffix (http-bind, ws-xmpp) to distinguish the endpoints if they are running on the same port. It spares the server some guessing what protocol is actually client going to use and provides nice separation.
What URL do you exactly use for BOSH and Websockets connection? In the former case it should be something like http://localhost:5280/http-bind and in the latter ws://localhost:5280/ws-xmpp.
What JS clients have you tried?

Categories

Resources