简体   繁体   中英

JAVA IPC on Windows

I want to open a named pipe using Java and extract the content of that archive (rar / zip /etc..) to a named pipe, then run Mplayer with the location of that pipe and play the movie.

I tried to open IPC in Java using this project CLIPC but, my code is freezing in the fifo.openWriter(); line

 FIFO fifo = new FIFO("jtpc_fifo");
 fifo.create();
 fifo.openWriter();

I tried , to create a small server Socket in java that waits for a connection and send the video file content as raw data, but I don't know how to tell mplayer to get raw data over the network.

I want to use a pipe, cause I think its the best solution no physical and large file to handle, its volatile and most flexible

This is what I am trying now, to use sockets but the java server socket accept the connection only after mplayer fails on timeout


mplayer http://localhost:5555/file.raw

 try{


  String file = "D:\\tmp\\lie.to.me.201.the.core.of.it-sitv.mkv";

  ServerSocket socket = new ServerSocket(5555);
  System.out.println("UnrarTest.main() START");
  Socket s = socket.accept();
  System.out.println("UnrarTest.main() ACCEPT");


  final InputStream sin = s.getInputStream();
  new Thread(){
    public void run(){
      try{
        while(true){
          if(sin.available() > 0){
            int read = sin.read();
            System.out.println((char)read);
          }
        }
      }catch(Exception ee){
        ee.printStackTrace();
      }
    }
  }.start();


  final OutputStream sout = s.getOutputStream();
  final FileInputStream fin = new FileInputStream(file);
  new Thread(){
    public void run(){
      try{
        while(fin.available() > 0){
          int in = fin.read();
          System.err.println(in);
          sout.write(in);
        }
      }catch(Exception ee){
        ee.printStackTrace();
      }

    }
  }.start();

}catch(Exception e){
  e.printStackTrace();
}

Windows "Named Pipes" are absolutely not related to POSIX named pipes, despite their names.

Windows Named Pipes are implemented in a client/server constitution. The server "creates" the pipe and the client contacts that created server. If the server "dies",... the pipe is automatically destroyed, whereas the file-system-based POSIX named pipes allow intermediate storage on the filesystem.

The Windows Named Pipes are so equivalent to socket usage, that one could easily be tempted to use sockets instead.

I'm not sure how well pipes are supported by CLIPC on Win32 platform (or Win32 itself, for that matter). To save your time use sockets, they are supported on Java/Win32.

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