- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在客户端-服务器之间的套接字连接中,我在一个线程中(在一个循环中)接收有关远程 pc 的信息以及另一个线程中的其他特定信息。
我的问题是因为当创建第二个线程时,第一个线程会立即停止,但是我想使用第二个线程接收的信息是必要的循环,如下所示的代码。
那么,如何在不停止某个线程的情况下同时执行两个线程呢?
// Entry point of first thread
procedure TSock_Thread2.Execute;
var
s: String;
begin
inherited;
while not Terminated and Socket.Connected do
begin
if Socket.ReceiveLength > 0 then
begin
s := Socket.ReceiveText;
if Pos('<|CUR|>', s)>0 then begin
TSTMouse := TSock_Thread5.Create(Socket);
TSTMouse.Resume;
Socket.SendText('<|GETCURSORICON|>'); // after this line, TSock_Thread2 stop your execution
end;
end;
end;
// Entry point of second Thread
procedure TSock_Thread5.Execute;
var
s, Ponteiro: string;
begin
inherited;
while not Terminated and Socket.Connected do
begin
if Socket.ReceiveLength > 0 then
begin
s := Socket.ReceiveText;
if Pos('<|MOUSEICON|>', s) > 0 then // receiving mouse icon here
begin
Delete(s, 1, Pos('<|MOUSEICON|>', s) + 12);
Ponteiro := Copy(s, 1, Pos('<|>', s) - 1);
if Ponteiro <> '' then
(Form1.LV1.Selected.SubItems.Objects[2] as TForm2).lblPoint.Caption := Ponteiro;
Sleep(100);
Socket.SendText('<|GETCURSORICON|>'); // request cursor icon again
end;
end;
end;
end;
最佳答案
你有两个线程从一个套接字读取?从一开始这通常是一个坏主意。如果你真的想要那样,那么你不能让它们同时读取,因为这不是套接字的工作方式。
任何给定的阅读器只能读取下一个字节或字节序列。没有内置控件可以说明为哪个线程指定了哪些字节。您需要弄清楚如何同步两个线程,以便它们各自知道何时允许读取。
另一个想法是只有一个线程从套接字读取。该线程可以读取字节序列,然后将它们分派(dispatch)给其他线程进行处理。
关于multithreading - 套接字 : how execute two threads simultaneously without stop?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39563434/
此函数返回一个 2 元组,其中包含列表的最小值和最大值: import Control.Arrow ((***), (>>>), (&&&)) import Data.Semigroup (getMi
我有两个 Java 进程,Processor 和 Simulator。 模拟器每5秒向File X写入规定的数据记录(10行文本)。 处理器不断读取该文件,等待 token 指示有效记录。代码是这样的
我有两个不同的应用程序必须协同工作。进程 1 作为时间源,进程 2 根据进程 1 提供的时间源执行操作。我需要运行进程 2 的多个副本。目标是让一个时间源进程同时向 5-10 个其他进程发出信号时间,
在我的 Backbone.js 应用程序中,我有以下模型和 View : var Operation = Backbone.Model.extend({ defaults: function(
请大家帮忙,这很重要。 我需要在不到 5 分钟的时间内下载大约 2000 张图像。所以我决定进行并行图片下载。 如果有人可以建议我进行并行下载的更好方法或告诉我哪里出错了,我将不胜感激。 在错误日志中
当我阅读 Clojure 代码(比如来自 GitHub 上的各个项目)时,有一些东西我不太理解:在 :require 表达式中,你应该使用 :as 当您仅使用您使用 :refer 引用的函数时?另外,
我在多个客户端连接的客户端服务器聊天程序的客户端实现上遇到问题。问题是我遇到的问题是我应该如何同时发送(聊天消息到另一个客户端)和接收(来自另一个客户端的聊天消息)?发生的情况是我总是发送数据但从不读
我有两个列表: List listA1 = GetFirstList(); List listA2 = GetSecondList(); 和A类定义 class A { public int
我使用了两个图像(img_heart_1 和 img_heart_2)。我有两种动画,一种是平移动画,另一种是缩放 text_anim.xml: animi(Animation),bounce_up.
考虑我有一个如下所示的运行方法,我正在尝试为 MyThread 创建四个线程。语句 1 到 3 可以由线程同时运行,也可以不同地运行。但是我想让Statement 4同时被线程执行。我可以在语句 4
对于新因素感到抱歉,但我正在阅读有关 mysql 的“太多连接”。 http://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html m
我正在尝试自定义约束 菜单栏类: import UIKit class ManuBar: UIView { override init(frame: CGRect) { sup
我正在使用尚未为 Swift 4 做好准备的第 3 方库,即打破独占内存访问规则 ( SE-0176)。 因此,我的控制台充满了这些警告: Simultaneous accesses to 0xb1a
我需要调用一堆 *.exe,这样我就可以调用一个记事本文件,其中存储了所有要调用的 *.exe 的所有完整路径,并使用该记事本文件(可以编辑)我想创建一个调用列表的父 exe,其中存在所有子 *.ex
我正在尝试制作一个具有单个服务器和多个客户端场景的客户端服务器聊天应用程序。我的服务器正在工作,但我无法让客户端工作。我正在使用 select() 函数来选择我应该 recv() 还是 send()。
我正在尝试为类似 Pokemon 的游戏编写一个 AI,除了所有的 Action 都事先为两个玩家所知(所有玩家都可以看到)。我已经记录了我需要的所有信息,例如伤害、准确度、暴击率等。 我以为我的目标
假设账户ABC(fund:1000) 发生一笔6000 的取款交易,同时从ATM 取款8000。那么交易将如何管理。数据库是否只打开一个连接并且不允许新连接到同一帐户?? .... 在这种情况下,当交
我一直在尝试将视频(来自我的网络摄像头)同时输出到文件('out.mkv')和管道: 文件获取过滤帧,管道:获取未过滤的原始视频。 我的帧速率是 30 fps。但是,我的文件输出中的帧速率要低得多。
我们需要在一台PC上驱动8到12个显示器,所有显示器都呈现单个3D场景图的不同 View ,因此必须使用多个图形卡。我们目前正在dx9上运行,因此希望移至dx11,以期使此操作变得更容易。 初步调查似
我想以编程方式同时不在XML文件中显示两个动画,它应该 ROTATE和TRANSLATE 我怎样才能做到这一点? 请以某种方式建议我?????? 这是ma代码:> ImageView snowImg1
我是一名优秀的程序员,十分优秀!