简体   繁体   English

Windows上的JAVA IPC

[英]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. 我想使用Java打开一个命名管道,并将该存档的内容(rar / zip / etc ..)提取到一个命名管道,然后在该管道的位置运行Mplayer并播放电影。

I tried to open IPC in Java using this project CLIPC but, my code is freezing in the fifo.openWriter(); 我试图使用该项目CLIPC在Java中打开IPC,但是我的代码在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. 我尝试过用Java创建一个小型服务器Socket,以等待连接并将视频文件内容作为原始数据发送,但是我不知道如何告诉mplayer通过网络获取原始数据。

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 这就是我现在正在尝试使用套接字,但是java服务器套接字仅在mplayer超时失败后才接受连接


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“命名管道”绝对与POSIX命名管道无关,尽管它们具有名称。

Windows Named Pipes are implemented in a client/server constitution. Windows命名管道以客户端/服务器构造实现。 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. 如果服务器“死亡”,...管道将自动销毁,而基于文件系统的POSIX命名管道则允许在文件系统上进行中间存储。

The Windows Named Pipes are so equivalent to socket usage, that one could easily be tempted to use sockets instead. Windows命名管道与套接字使用等价,因此很容易诱使您使用套接字。

I'm not sure how well pipes are supported by CLIPC on Win32 platform (or Win32 itself, for that matter). 我不确定Win32平台上的CLIPC(或Win32本身)对管道的支持程度。 To save your time use sockets, they are supported on Java/Win32. 为了节省您的时间,请使用套接字,Java / Win32上支持它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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