plasma-umass / doppio

Breaks the browser language barrier (includes a plugin-free JVM).

Home Page:http://plasma-umass.github.io/doppio-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doppio with the browser directly

amahdy opened this issue · comments

Related to #509

Majority of Java usage right now is on the server-side, as a backend. Also having an applet-like app is -although great technical wise- not amazing from user experience point of view.

I'm trying to experiment something on this side, which is running a backend server using doppio, and use an iframe in the browser to interact with it. But I'm failing and running out of ideas. Thus I need some help :)

What I'm trying to do? Getting a minimal embedded jetty server into a jar file to run in doppio. It's not working properly but still if it works then it's going nowhere.

It will theoretically open port 8080 on the host machine and listen for connection. But the host is a browser and it does not understand what is listening to port 8080.
I'm trying to fake it to make the process locate the iframe instead and interact with it. In the previous example, that iframe can be as simple as a blank page pointing to localhost:8080 and the end result will be getting <h1>Hello World</h1> in it.

From what I understand, you are running a server on port 8080 in Doppio in the browser, and trying to load an iframe from http://localhost:8080? If that is true, then it is unfortunately impossible due to browser restrictions.

For security reasons, you actually cannot open an arbitrary port or create an arbitrary TCP connection in the browser. You can open a WebSocket connection to an outside server, send an outgoing HTTP request, or open a WebRTC connection, but cannot open a raw TCP socket or accept HTTP requests. So, what you are trying to do is impossible!

Doppio currently supports outgoing TCP connections to natively running servers by wrapping TCP connections in a WebSocket connection using Websockify. The natively running server must also be wrapped in Websockify, which proxies data sent via a WebSocket connections through the server as a raw TCP connection.

Doppio does not support incoming TCP connections from outside sources as that is currently infeasible.

(Sidenote: If Doppio were modified to run in Browsix, which is the next evolution of the OS primitives emulated by Doppio, then it could accept incoming TCP connections from other programs running in Browsix. It still would not be able to accept a real TCP/HTTP connection from the browser, though.)

(Sidenote 2: It's possible that someone could hack something super super crazy together using ServiceWorkers, but you would need to 1) emulate incoming TCP connections, 2) translate outgoing data from the server from raw bytes into service worker responses, 3) make sure it's even feasible -- I think ServiceWorkers can be arbitrarily killed if they execute for too long.)

I did not manage to run jetty and make it listen to port 8080. All my attempts failed.
I was trying to find a way to fake the sockets layer so that instead of interacting with the host machine and trying to listen to a port, directly read a given iframe and dump the server output into it.

Outside Doppio and in a real jvm, if I run jetty it will ask the host machine to open port 8080 and listen to incoming connection. In the provided example, any incoming connection will receive the string Hello World. So step number one I'm trying to fake this machine layer and directly output the string into an iframe or something similar.

I see. You'll need to hack the socket native methods to do that.

Let me know if you have any success. I tried to fix up the outgoing TCP socket implementation further in a branch, but ran into some bugs related to Websockify and was not able to proceed further. Whatever you do to "fake" sockets might be useful to refactor Doppio so it can be plugged into Browsix and use its socket implementation.

I have very limited time to help in any direct way, but I can answer questions when/if you have any.

I am interested in something similar, but without access to the networking and wondering if it is possible. I wanted to run (and interact with) tools written in Java from browser. In particular I wanted to run [TLA+|https://github.com/tlaplus/tlaplus] in the browser.