在post(1)循环中阻塞的线程内处理postthreadmessage()或使用“Event Driven Sockets” [英] Handle postthreadmessage() inside a thread which is blocking in while(1) loop or use “Event Driven Sockets”

查看:125
本文介绍了在post(1)循环中阻塞的线程内处理postthreadmessage()或使用“Event Driven Sockets”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器多客户端udp应用程序。存在具有单个套接字(套接字#1)的单个线程(线程#1)以连续地从客户端#1接收数据。此接收线程的任务是在其套接字上连续接收数据。



我在服务器应用程序GUI上有一个向客户端#1发送数据的按钮。当按下这个按钮时,我希望我的接收线程暂停接收并在套接字#1上发送一些数据,当发送数据时,恢复连续接收。



如何可以这样做吗?如果我按下按钮时甚至postthreadmessage(),则接收线程不检查这些发布的消息,因为它总是在接收消息的while循环内。如何检查对应按下按钮的已发布消息?



编辑:另一个建议



如果我让我的插座事件驱动?即,只要在套接字上有一些数据可供读取,就会生成FD_READ事件并且我可以在套接字上读取,每当我想在套接字上写入一些数据时,我生成一个事件FD_WanttoWrite,然后将数据写入套接字。有类似的东西吗?



(我知道FD_READ,但是当我希望在Socket上写东西时我不确定FD_WanttoWrite)

I have a single server multiple client udp application. There is a single thread (thread#1) with a single socket (socket#1) to receive data from client#1 continuously. The task of this receiving thread is to continuously receive data at its socket.

I have a button which says "Send data to Client#1" on Server application GUI. When this button is pressed, I want my receiveing thread to suspend reception and send some data on socket#1 and when data is sent, continuous reception is resumed.

How can this be done? If I even postthreadmessage() when button is presses, the receiving thread has no check for these posted messages since it is always inside the while loop receiving messages. How can it check for posted message corresponding to buttons pressed?

Another Suggestion

What if I make my socket "Event Driven"? i.e. whenever there is some data available at socket to be read, FD_READ event is generated and I can read on socket, and whenever I want to write some data on the socket, I GENERATE AN EVENT FD_WanttoWrite and then data is written on the socket. Is something similar to this possible?

(I know about FD_READ but I am not sure about FD_WanttoWrite when I wish to write something on Socket)

推荐答案

您可以使用主线程(或只是另一个)来写入数据。
You may use the main thread (or just another one) for writing data.


这篇关于在post(1)循环中阻塞的线程内处理postthreadmessage()或使用“Event Driven Sockets”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆