How to create http server in browser using javascript?
Asked Answered
I

1

5

I am implement html5 player. It is similar to streaming, but it is not strictly streaming.

First I tried. Using Media Source Extensions. But I can not implement seeking. I do not know the byte offset.

So I thought. If you can create an http server in your browser, I can only respond to range requests.

Can I create http server in browser using javascript? It is support mobile/pc browser. It is must support mobile/pc browser.

Ial answered 6/9, 2017 at 3:23 Comment(4)
The short answer is no, the browser is a browser, and can't be a server. It doesn't have permission to access the operating systemPrune
You cannot. If you are using a browser which allows extensions use them eg: chrome.google.com/webstore/detail/web-server-for-chrome/…Supplicant
You could build it using WebRTC, which allows P2P communication. It wouldn't be a "real" HTTP server though.Funchal
It is possible to run a "real" HTTP server in a browser using a virtual machine with a reverse proxy tunnel. A server in WebVM can connect to clients through Tailscale Funnel, for example.Antisthenes
P
6

Can I create http server in browser using javascript?

No. Regular browser Javascript cannot create a web server. Browser Javascript was not given that capability and since you cannot create your own TCP server either, you cannot even build your own http server.

To do something like that, you'd have to have a browser extension that used some native code to set up an http server. But, even if you did that, you'd probably have firewall issues since most clients are not directly reachable by other clients unless they happen to be on the same sub-network as clients are usually behind a firewall.

Pusher answered 6/9, 2017 at 3:44 Comment(5)
It is actually possible to run a server on the client-side without a browser extension (using WebContainers, for example).Antisthenes
@AndersonGreen - Please elaborate on how that is possible. What I see in your link does not describe creating an http server that accept incoming requests and does something useful (like connecting to a database). In addition, browsers generally run in an environment where incoming requests are blocked by a firewall anyway.Pusher
I was apparently wrong here: this feature is not yet supported in WebContainers, due to current limitations of web browsers.Antisthenes
Nonetheless, it is possible to simulate a client-server connection between two browsers using a WebRTC connection.Antisthenes
@AndersonGreen - Most people would call that a peer to peer connection, including the webRTC site itself. Plus, the question here is can you create an http server which webRTC is not. But, yes you can connect two browsers with webRTC (sometimes) and that can be useful - though not the question that was asked here (7 years ago).Pusher

© 2022 - 2024 — McMap. All rights reserved.