Does XMPP server MongooseIM work with BOSH or WebSocket? - javascript

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?

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!

From javascript browser client-side to Postgresql [duplicate]

I have a c# tcp server, I want to connect to the server via a html client page.
The problem: There is no simple way to create TCP sockets in Javascript on a browser side. Although solutions like Websockets allow to create something that resemble sockets, you can use them to connect only to servers that support Websockets. Not to any random servers that know nothing about HTTP.
so is there a solution to connect to my srver.
No. There just isn't. The browser is a tightly locked down environment. The only socket connection that you can open from JavaScript is WebSocket. Since it's your server, adding WebSocket support shouldn't be too complicated, and there are WebSocket libraries available for C#.
Maybe someone else will have an idea for you, but...
The best solution I can think of is for your server to support websockets.
The situation you described - along with connectivity issues for traffic passing through proxies and routers - is one of the reasons Websockets were introduced in the first place.
Bare in mind that Websockets can send and receive binary data. It's just that javascript make it more comfortable to write text based messages.
Also, many NAT routers, Proxies and firewalls will block raw TCP/IP communication while allowing Http communication to pass through. This is why you have a better chance at connection establishment and retention when implementing the Websocket protocol.

Web socket client JavaScript?

i created TCP Client Using Web Socket 'JavaScript' and it can connect to C# TCP Server but i can't replay in C# to handshaking sent by JavaScript TCP Client
Please Help !
thanks.
There's no way we can help you here in any specific way without seeing your code on both client and server. webSocket is a protocol, not just a plain TCP connection. For your C# server to successfully accept a webSocket connection from any client, it must follow the entire webSocket protocol.
This reference Writing WebSocket Servers provides a pretty good summary of what a server has to do in order to successfully "speak" webSocket. Unless this is merely a learning exercise for you, you will probably want to get a library/class for C# that already implements a webSocket server as I'm sure there are many.
To give you a general idea, all webSocket connections start with an HTTP request that includes an "upgrade" header, a security key and a version. If the server agrees to the upgrade, then it responds with a security key. At that point, the two sides switch from HTTP to the webSocket protocol on that same socket and from then on, all data is then sent using the webSocket Frame format. This information is all outlined in the earlier MDN reference about creating webSocket servers.
Here is an article about writing webSockets servers in C#:
MDN: Writing a WebSocket server in C#

html javascript connect to raw socket

I have a c# tcp server, I want to connect to the server via a html client page.
The problem: There is no simple way to create TCP sockets in Javascript on a browser side. Although solutions like Websockets allow to create something that resemble sockets, you can use them to connect only to servers that support Websockets. Not to any random servers that know nothing about HTTP.
so is there a solution to connect to my srver.
No. There just isn't. The browser is a tightly locked down environment. The only socket connection that you can open from JavaScript is WebSocket. Since it's your server, adding WebSocket support shouldn't be too complicated, and there are WebSocket libraries available for C#.
Maybe someone else will have an idea for you, but...
The best solution I can think of is for your server to support websockets.
The situation you described - along with connectivity issues for traffic passing through proxies and routers - is one of the reasons Websockets were introduced in the first place.
Bare in mind that Websockets can send and receive binary data. It's just that javascript make it more comfortable to write text based messages.
Also, many NAT routers, Proxies and firewalls will block raw TCP/IP communication while allowing Http communication to pass through. This is why you have a better chance at connection establishment and retention when implementing the Websocket protocol.

Can I connect to irc, icq, sip, etc services using WebSockets providing I have some sort implementation of those protocols in JavaScript?

I would like to connect to to irc, icq, sip, etc services using WebSockets.
Assuming I have some sort implementation of those protocols in JavaScript ?
Is that possible? I don't seems to understand limitations of WebSockets comparing to regular sockets.
No, you can't, at least not directly.
WebSockets allow real-time messaging between a browser and a WebSocket server, but they have their own layer 7 protocol for encapsulating those messages.
They don't provide access to a pure TCP (or UDP) socket over which you can implement existing protocols.
Absolutely!
The caveat is that you need something to bridge between the WebSocket transport protocol of the browser and the raw TCP socket of the existing service. For example, something like websockify (disclaimer: I created websockify). Another caveat is that websockify only supports TCP targets (WebSocket is TCP only right now so supporting UDP targets would be a little odd anyways).
The websockify project actually includes two proof of concept HTML/Javascript pages to communicate with IRC and telnet. If you are interested in leveraging websockify to build HTML/Javascript clients for some common TCP protocols, I might even pull them into the websockify repo as examples (assuming they are well coded and under an open source license.
An alternative to websockify is to integrate websocket server-side support directly into the servers you wish to communicate with. It's not all that difficult to add support. WebSocket has a very simple framing and while the handshake is compatible with HTTP servers it's actually much more restricted and simple and doesn't require a full HTTP parser. For example, libvncserver 0.9.9 now supports both regular VNC connections and VNC connections over WebSocket. This allows noVNC (which I also created) to connect directly to a libvncserver based VNC server without requiring websockify.
Inspircd has an unofficial module you can install called m_websockets, to allow connection. A server that has the module installed and setup will allow you to connect to the server via webbsockets.
https://github.com/barosl/inspircd-m_websocket
Extending on #kanaka's websockify, this project seems to do it:
A HTML5 irc-client, made with websocket and websockify.
[Has] support for autojoin, privmsg channel, topic, join, userlist, part, nick.
https://github.com/confact/dunirc
No, not with websockets, but you can with http.
Samy Kamkar gave a black hat talk about this.

Categories

Resources