How can I code a server/client video and audio streaming application?

后端 未结 3 1409
时光取名叫无心
时光取名叫无心 2020-12-13 16:32

I have to create a client/server system to stream video and audio. It would be very simple. Like youtube style. The server should attend clients providing a list of medias f

3条回答
  •  一向
    一向 (楼主)
    2020-12-13 16:55

    Check out the Java Media Framework (it has tutorials): http://java.sun.com/javase/technologies/desktop/media/jmf/

    Does this even work?

         while(true) {
            Runnable r = new ThreadedEchoHandler(incoming, i);
            Thread t = new Thread(r);
            t.start();
            i++;
         }
    

    I think your code would produce a bunch of threads with incoming socket connections... what you probably want to do is this:

         while(true) {
            Runnable r = new ThreadedEchoHandler(incoming.accept(), i);
            Thread t = new Thread(r);
            t.start();
            i++;
         }
    

    The ThreadedEchoHandler should take a Socket instead of a ServerSocket. Accept blocks until a client connects, otherwise you'll be spawning an infinite number of threads without a connection... I don't think you have anything that will stop you from doing that at the moment.

提交回复
热议问题