请问一下大家 关于ReadFile 从Named Pipe 中读取数据的 问题 。

Forrest 2016-03-09 11:41:17
请问一下大家 关于ReadFile 从Named Pipe 中读取数据的 问题 。。。。

具体问题如下 :

我采用多线程 两个 软件之间 用 Pipe 管道通信, 一个 做Named Pipe Server , 另一个做Pipe Client
现在实现了 Client 客户端 想Server 服务器端 发送消息单向通信, 我想在想用 Server 端接收到数据后,再回传给 Client ,但是 问题出现了:

首先 我在Server端 创建Named Pipe句柄, 设置了Meaasge Mode, 并创建 了一个线程,在线程中 调用了ReadFile 函数采用 重叠I/O ,Overlapped 操作, 一直Listening 监听,当管道中有消息时候,也就是 客户端发送消息的时候,能正常接收到数据。

但是 我又在 Client 客户端 中创建了一个线程,也同时 在一个循环里 调用 ReadFile 函数,监听 管道中的数据, 程序正常运行,
在Client 端中 ,我用一个菜单命令中 调用了 WriteFile 函数 这个时候 Client 端程序 整个没响应卡主了???? // 不知道问题出在那里?

难道同一个 Named Pipe 不能同时 Listening 监听吗?
为仕么在我 客户端中调用 WriteFile 函数的时候,程序卡死 了 ?
...全文
307 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Forrest 2016-03-14
  • 打赏
  • 举报
回复
引用 8 楼 schlafenhamster 的回复:
http://www.codeproject.com/Articles/2996/Universal-Console-Redirector
哦,谢谢,我先去看看!
schlafenhamster 2016-03-11
  • 打赏
  • 举报
回复
搜索“Redirector”
Forrest 2016-03-11
  • 打赏
  • 举报
回复
引用 5 楼 schlafenhamster 的回复:
Whenever a pipe write operation occurs, the system first tries to charge the memory against the pipe write quota. If the remaining pipe write quota is enough to fulfill the request, the write completes immediately. If the remaining pipe write quota is too small to fulfill the request, the system will try to expand the buffers to accommodate the data using nonpaged pool reserved for the process. The write will block until the data is read from the pipe so that the additional buffer quota can be released. Therefore, if your specified buffer size is too small, the system will grow the buffer as needed, but the downside is that the operation will block. If the operation is overlapped, a system thread is blocked; otherwise, the application thread is blocked.
哦,非常感谢你的回复 ! 两个进程 之间通过 Named Pipe 的双向 实时(数据交换 )通信 最好 在客户端创建 两个 Named Pipe ,分别作 接收和发送? 不知道 有没有 更好的方案?
schlafenhamster 2016-03-10
  • 打赏
  • 举报
回复
Whenever a pipe write operation occurs, the system first tries to charge the memory against the pipe write quota. If the remaining pipe write quota is enough to fulfill the request, the write completes immediately. If the remaining pipe write quota is too small to fulfill the request, the system will try to expand the buffers to accommodate the data using nonpaged pool reserved for the process. The write will block until the data is read from the pipe so that the additional buffer quota can be released. Therefore, if your specified buffer size is too small, the system will grow the buffer as needed, but the downside is that the operation will block. If the operation is overlapped, a system thread is blocked; otherwise, the application thread is blocked.
Forrest 2016-03-10
  • 打赏
  • 举报
回复
引用 3 楼 schlafenhamster 的回复:
A pipe can be created such that communication can take place in only one direction (either inbound from the client to the server or outbound from the server to the client) or in two (bidirectional).
你好,非常感谢,那我怎么做 才能把 Cilent 客户端 的 ReadFile 函数返回,退出监听状态,然后切换可以发送,用WriteFile 函数发送数据到服务器端哪?。 Nemed Pipe 可以双向通信,不可以同时做双向通信? 可以这么理解吗? 那怎么才能做到 分时 双向通信哪?
赵4老师 2016-03-09
  • 打赏
  • 举报
回复
《Windows核心编程》
schlafenhamster 2016-03-09
  • 打赏
  • 举报
回复
A pipe can be created such that communication can take place in only one direction (either inbound from the client to the server or outbound from the server to the client) or in two (bidirectional).
Forrest 2016-03-09
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
《Windows核心编程》
首先还是谢谢,不过,大哥你回复的太笼统了!

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧