一些实现命名管道通信服务应用程序的来源或有关它的帮助

发布于 2024-10-15 17:03:46 字数 313 浏览 8 评论 0原文

我正在实现我自己的命名管道客户端/服务器类,但我遇到了太多麻烦,而且互联网上没有太多信息。 我已经找到了很多使用管道但使用 vlc 应用程序的实现,但我正在使用服务应用程序。

我也接受有关如何使用管道的提示。

我的实际问题是: 虽然服务器应用程序只收到来自客户端的一条消息,但此后我的服务器无法再使用 PeekNamedPipe() 。 我从 GetLastError 收到的错误消息是“管道的另一端有一个进程”,但是......我不知道该怎么解决这个问题。 如果我关闭客户端应用程序,我收到的消息是“管道正在关闭”,此后我无法建立客户端通信。

tks

I'm implementing my own named pipe Client/Server class, but I'm getting too much troubles and no much information about on internet.
I already found a lot of implementation with pipes but with vlc application but I'm working with service applications.

I accept hints about how to work with pipes too.

My actual problem is:
While server the app just receive one message from the client, after this my server can't use PeekNamedPipe() any more.
My error message that I get from GetLastError is "there is a process on other end of the pipe", but.... I don't know what to solve do with this.
If I close the client app, the message I get is "The pipe is being closed", and I can't establish a client communication after this.

tks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

亚希 2024-10-22 17:03:46

哦哦我发现问题了。
我正在阅读一些 Windows 文章,发现我必须使用 after peek 和 after disconnect 来连接到命名管道。这是有道理的。

ConnectNamedPipe(FPipeHandle, nil) 和 PeekNamedPipe(FPipeHandle, nil, 0, nil, @LBytesSize, nil) 之后

执行操作后我必须调用 DisconnectNamedPipe(FPipeHandle);
释放进程。

tks

Oooo I found the problem.
I was reading some windows articles and I found out that I must connect to the named pipe using after peek and after disconnect. It make sense.

ConnectNamedPipe(FPipeHandle, nil) and after PeekNamedPipe(FPipeHandle, nil, 0, nil, @LBytesSize, nil)

And after doing my operation I must call DisconnectNamedPipe(FPipeHandle);
To free the process.

tks

誰ツ都不明白 2024-10-22 17:03:46

我认为在 Vista 或 7 中运行应用程序时会遇到一些麻烦。

在 XP 下,服务和客户端应用程序之间的通信没有问题。

但“感谢”Vista 和 7 引入的新 UAC 和安全策略,您需要设置一些安全参数。

请参阅我在开源框架的实施和测试过程中发现的内容

您有一个命名管道客户端和服务器通信的工作示例,还使用作为服务运行的服务器进行了测试,在我们的源代码存储库中

I think you'll get some troubles when running your application in Vista or Seven.

Under XP, no problem of communication between a service and a client application.

But "thanks" to the new UAC and security policy introduced with Vista and Seven, you need to set some security parameters.

See what I found out during implementation and testing of our Open Source framework.

You have a working example of Named Pipe client and server communication, also tested with the server running as a service, in our source code repository.

妖妓 2024-10-22 17:03:46

如果您有一些示例代码,请注意您需要在表单上创建的 GUI 组件:

发送方单元:

procedure TForm1.FormCreate(Sender: TObject);
var
   FSA : SECURITY_ATTRIBUTES;
   FSD : SECURITY_DESCRIPTOR;
   pch1: shortstring;
begin
   InitializeSecurityDescriptor(@FSD, SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(@FSD, True, nil, False);
   FSA.lpSecurityDescriptor := @FSD;
   FSA.nLength := sizeof(SECURITY_ATTRIBUTES);
   FSA.bInheritHandle := True;

   Pipe:= CreateNamedPipe(PChar('\\.\pipe\<test>'),
                          PIPE_ACCESS_DUPLEX or FILE_FLAG_WRITE_THROUGH,
                          PIPE_TYPE_MESSAGE or PIPE_READMODE_MESSAGE or PIPE_NOWAIT,
                          PIPE_UNLIMITED_INSTANCES,
                          1024,
                          1024,
                          50,
                          @FSA);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   buffer: shortstring;
   dw : dword;
   b1 : boolean;
begin
   buffer:= Edit2.Text;
   WriteFile(Pipe, buffer, sizeof(buffer), dw, nil);
end;

接收方单元:

procedure TForm1.FormCreate(Sender: TObject);
var
   FSA : SECURITY_ATTRIBUTES;
   FSD : SECURITY_DESCRIPTOR;
begin
   InitializeSecurityDescriptor(@FSD, SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(@FSD, True, nil, False);
   FSA.lpSecurityDescriptor := @FSD;
   FSA.nLength := sizeof(SECURITY_ATTRIBUTES);
   FSA.bInheritHandle := True;

   Pipe:= CreateFile(PChar('\\.\pipe\<test>'),
                     GENERIC_READ or GENERIC_WRITE,
                     0,
                     @FSA,
                     OPEN_EXISTING,
                     0,
                     0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   buffer: shortstring;
   dw : dword;
begin
   ReadFile(Pipe, buffer, sizeof(buffer), dw, nil);
   edit1.Text := buffer;
end;

希望这会有所帮助。

hier you have some sample code, notice the GUI components you will need to create on your form:

Sender unit:

procedure TForm1.FormCreate(Sender: TObject);
var
   FSA : SECURITY_ATTRIBUTES;
   FSD : SECURITY_DESCRIPTOR;
   pch1: shortstring;
begin
   InitializeSecurityDescriptor(@FSD, SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(@FSD, True, nil, False);
   FSA.lpSecurityDescriptor := @FSD;
   FSA.nLength := sizeof(SECURITY_ATTRIBUTES);
   FSA.bInheritHandle := True;

   Pipe:= CreateNamedPipe(PChar('\\.\pipe\<test>'),
                          PIPE_ACCESS_DUPLEX or FILE_FLAG_WRITE_THROUGH,
                          PIPE_TYPE_MESSAGE or PIPE_READMODE_MESSAGE or PIPE_NOWAIT,
                          PIPE_UNLIMITED_INSTANCES,
                          1024,
                          1024,
                          50,
                          @FSA);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   buffer: shortstring;
   dw : dword;
   b1 : boolean;
begin
   buffer:= Edit2.Text;
   WriteFile(Pipe, buffer, sizeof(buffer), dw, nil);
end;

Receiver unit:

procedure TForm1.FormCreate(Sender: TObject);
var
   FSA : SECURITY_ATTRIBUTES;
   FSD : SECURITY_DESCRIPTOR;
begin
   InitializeSecurityDescriptor(@FSD, SECURITY_DESCRIPTOR_REVISION);
   SetSecurityDescriptorDacl(@FSD, True, nil, False);
   FSA.lpSecurityDescriptor := @FSD;
   FSA.nLength := sizeof(SECURITY_ATTRIBUTES);
   FSA.bInheritHandle := True;

   Pipe:= CreateFile(PChar('\\.\pipe\<test>'),
                     GENERIC_READ or GENERIC_WRITE,
                     0,
                     @FSA,
                     OPEN_EXISTING,
                     0,
                     0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
   buffer: shortstring;
   dw : dword;
begin
   ReadFile(Pipe, buffer, sizeof(buffer), dw, nil);
   edit1.Text := buffer;
end;

hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文