mesutpiskin / opencv-live-video-stream-over-http

:satellite: OpenCV is a sample project that is read from the video source (Camera, File System, NVR, DVR etc.) and displays the processed image via the http protocol.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I access this in multiple tabs in browser?

opened this issue · comments

When I open this page in two tabs it worked in one tab.

How can I access this in multiple tabs in browser?

I think you need to open multiple server socket connections. I do not know this, you can look at the java server sockets documents.

How to open multiple server socket connections?

I searched on internet for this.

But , I can't solve this.

Can you give more information?

A new tab opens a new socket connection, I don't know how to fix this.
Maybe use other http server application, jetty, undertow, etc.

Hi @mesutpiskin , first let me say many thanks for your example. It helped me greately in my own development.
@poorvajappja I solved the problem that you are having by developing the server in spring boot using a StreamingResponseBody but I based all the other things on @mesutpiskin example. Each new session opens it's own VideoCapture so they can receive the video. I will upload a demo project to github soon.

I'm happy for you, that's great. If you share your project, can you add a link here too?

In the end the solution is a little bit different than I described originally. You can see for yourself. Here is the link

@poorvajappja I converted this single-use server to multi-clients and it's here. I'm sure it's not "industrial strength" but it seems to work. I was happy with the single-use here but since you mentioned it, I practiced multi-threading and socket programming to learn. It's still pure Java and OpenCV - no additional libraries required which is why I liked this one.

@tom131313 it worked. thank you very much.

@mesutpiskin @tom131313

I want to send the String contineously over http socket.

   ac  f=new ac();
  String string = f.getSt();

  byte[] byteArray = string.getBytes();

  os.write("HTTP/1.0 200 OK\n".getBytes());
  os.write(new String("Content-Length: " + byteArray.length + "\n").getBytes());
  os.write("Content-Type: text/html\n\n".getBytes());

  os.write(byteArray);

I want to get and send the the String over the socket contineously .

This project get and sent the webcam image over http socket contineously.

But, I want to get and send the the String over the socket contineously .

How can I do this ?

I asked this question because I did't know more about http stream in java.

and I can't understand the following codes

   stream.write(("HTTP/1.0 200 OK\r\n" +
            "Connection: close\r\n" +
            "Max-Age: 0\r\n" +
            "Expires: 0\r\n" +
            "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" +
            "Pragma: no-cache\r\n" +
            "Content-Type: multipart/x-mixed-replace; " +
            "boundary=" + boundary + "\r\n" +
            "\r\n" +
            "--" + boundary + "\r\n").getBytes());

and this

outputStream.write(("Content-type: image/jpeg\r\n" +
                "Content-Length: " + imageBytes.length + "\r\n" +
                "\r\n").getBytes());