Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doppio with the browser directly #510

Open
amahdy opened this issue Jan 10, 2018 · 4 comments
Open

Doppio with the browser directly #510

amahdy opened this issue Jan 10, 2018 · 4 comments

Comments

@amahdy
Copy link
Contributor

amahdy commented Jan 10, 2018

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.

@jvilk
Copy link
Member

jvilk commented Jan 10, 2018

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.)

@amahdy
Copy link
Contributor Author

amahdy commented Jan 10, 2018

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.

@jvilk
Copy link
Member

jvilk commented Jan 10, 2018

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.

@iilyak
Copy link

iilyak commented Jan 17, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants