简体   繁体   中英

Redirecting HTTP Requests

I am working on creating plug-and-play software for cameras behind a firewall. To do that, the camera has a command that tells it to connect to a server of mine (over http), in which I can talk to it in http.

I need to export this connection to users, so that when I get http requests, I forward them directly to the camera, and forward the responses back to the user.

My initial idea was just to use tcp - get the camera connection using tcp, and continuously wait for user connections. When I get a user connection - I forward everything from it to the camera, and from the camera to it. In other words - plain old port redirection.

The problem begins when the user needs to have several active connections to the camera. I hoped this would not be an issue - but I have found out (or at least that's what I think happens) that browsers actually open several connections to the same site to download files.

Now I have no choice but to write code that actually reads the http request, dispatches it to the camera, waits for the camera's response, and sends it back. That is the only way to allow multiple connections to the same camera using just one connection (as far as I can see).

My question is - is there any existing code to do this? Libraries? Software? Or is there any better way to do what I'm trying to do?

EDIT: Well, apparently I was wrong about the browser creating several connections to the server. What actually happens is that the server returns HTTP 1.0 responses, and as I have found out, HTTP 1.0 allows a single request (and response) per connection. What I was seeing is the browser just leaving the used connection it has opened earlier open, and opening a new one for a new request.

However, I still had to do HTTP message forwarding myself (I only implemented "text/html", "text/plain" and some other custom content type which is used by the camera). So for instance, the browser doesn't show pictures at all. So if anyone knows about any code that does http message forwarding (or an application that does it), I would love to hear it.

As a side note - I have checked the proxy feature of httpd (apache). Not only is it very complicated, it also seems to allow only one proxy connection on the machine. So I abandoned that direction and implemented basic forwarding myself.

Thanks

Web servers embeded in Cameras are not able to scale so you should rather query the camera, put the images in a cache and then push the latest images to each client (preferably using presistent HTTP 1.1 connections).

How to do it depends on your latency needs (delay between refreshes) and how many clients will join the game.

If sounds like a job for G-WAN (a fast server with C, C++, D, Java, and Objective-C/C++ scripts to generate dynamic contents), but I might be partial since I am part of the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM