WinRT StreamSocket - 强制关闭现有连接(WinRT StreamSocket - existing connection forcibly closed)
尝试使用
StreamSocket
从服务器下载数据时,遇到错误:现有连接被强行关闭
我使用
StreamReader
从InputStream.AsStreamForRead().
读取数据InputStream.AsStreamForRead().
奇怪的是,这适用于我下载的第一条消息,但会为下一条消息抛出上述异常。
错误不会立即发生,它确实设法读取大部分消息,但在某些时候它会阻塞sr.ReadLine(),然后抛出异常。 请参阅下面的代码段:
while (true) { str = sr.ReadLine(); if (str != ".") { if (str.StartsWith(@"..")) sb.Append(str.Substring(1) + "\r\n"); else sb.Append(str + "\r\n"); } else break; }
When attempting to download data from a server using
StreamSocket
, I encounter an error:An existing connection was forcibly closed
I use a
StreamReader
to read data fromInputStream.AsStreamForRead().
Strangely, this works fine for the first message I download, but throws the above exception for the next message.
The error doesn't happen immediately, it does manage to read most of the message, but at some point it blocks on sr.ReadLine() and then an exception is thrown. See snippet below:
while (true) { str = sr.ReadLine(); if (str != ".") { if (str.StartsWith(@"..")) sb.Append(str.Substring(1) + "\r\n"); else sb.Append(str + "\r\n"); } else break; }
原文:https://stackoverflow.com/questions/14292993
最满意答案
这种情况不适合使用线程。 因此,避免使用线程。
The situation is not suitable to use thread. Thus, avoid using thread.
相关问答
更多-
线程顺序执行中的问题(Problems in thread order execution)[2021-12-28]
危险! 危险! 这根本不是做线程的方法。 一点也不。 您需要抛弃此代码并重新开始。 首先,您不应该使用sleep()进行“同步”。 其次,你不能从次要线程中UIKit ; 你的线程看起来像是在弄乱显示器。 您可以执行的操作非常有限。 最后,你几乎不再想要使用NSThread了。 使用GCD队列或NSOperationQueue。 Danger! Danger! That simply is not the way to do threading. Not at all. You need to throw ... -
1-3和7在同一个线程上执行(调用4) 5,6在相同的线程上执行,这是提供CompletableFuture结果的相同线程(在步骤4中,很可能不是用于调用restTemplate的相同线程)。 AsyncRestOperations是一个接口,因此内部发生的事情将取决于底层实现。 如果您使用的是NIO Rest Client,则会在NIO客户端的内部事件循环池中执行Rest调用(5和6可能不是您想要的 - 请参阅thenApplyAsync,然后是thenCompose)。 您正在使用Async Block ...
-
事件驱动的未来
- 线程池(Event Driven Future [2023-07-22]- Thread Pool) 你可能想看看ThreadPoolExecutor.afterExecute()方法。 它在每个任务完成后调用。 您可以创建ThreadPoolExecutor的自定义子类,该子类具有您所需的基于事件的回调行为。 you might want to check out the ThreadPoolExecutor.afterExecute() method. it's called after each task completes. you could create a custom subclass of ... -
这种情况不适合使用线程。 因此,避免使用线程。 The situation is not suitable to use thread. Thus, avoid using thread.
-
Java - 重用线程池(Java - Reusing Thread Pool)[2021-11-15]
我不一定会说它本身就是劣质设计,但需要考虑一些事情。 就个人而言,我喜欢线程池,如果使用正确,它是一个强大的解决方案。 性能下降的原因是,当固定池大小为2时,一次只能运行两个线程。 有可能你需要一个更大的数字 - 可能是10,可能是100 - 但至少你可以设置它,以便你不会耗尽内存。 也就是说,如果原始设计内存不足,因为创建的线程太多,你肯定需要一次限制活动线程的数量,所以你的性能会受到一些打击...它只是不需要是全有或全无。 您还可以使用无限的执行程序线程池,假设正在运行的线程确实及时返回,这样您仍然不会 ... -
PHP线程池(PHP Thread Pool)[2022-03-28]
您应该先阅读: https : //gist.github.com/krakjoe/6437782GoGo中没有构造函数接受ArrayList。 在GoGo定义构造函数,如下所示: class GoGo implements Runnable{ ArrayList some; public GoGo(ArrayList received_array){ this.some = received_array; } .. } There is no constructor in GoGo that accepts an ArrayList 为每个任务类型都有一个单独的队列 - 您可能没有成千上万的任务类型 。 这些中的每一个都可以是例如任务的静态成员。 然后addJob()实际上是Task的ctor,它是完全类型安全的。 然后定义任务类型的编译时列表,并通过模板元编程(for_each)访问它。 它会更快,因为你不需要任何虚拟调用fnptr / std::function<>来实现这一点。 这只有在您的元组代码看到所有Task类时才会起作用(因此您不能通过从光盘加载图像来向已经运行的可执行文件添加Task的新后代 - 希望这不是问题)。 te ...我认为您可能有机会了解目前为C ++标准化提出的可恢复功能 。 该提案尚未获得批准,但Visual Studio 15 CTP实现了该提案,因此您可以尝试制作原型(如果可以使用MSVC编译器)。 Gor Nishanov(最新提案论文的作者之一)描述了一个非常相似的例子,在他的CppCon讲座中,从23:47开始计算斐波纳契的“父母窃取计划”: https : //www.youtube.com/watch? v = KUhSjfSbINE 但是,请注意,我找不到任何spawnable源代码/样本,因 ... 直接来自N3337( c ++ 11标准草案), [futures.async] / 5 ,重点是: 同步 :无论提供的策略参数如何, 异步调用与([intro.multithread])f的调用同步。 [注意:即使将相应的将来对象移动到另一个线程,此语句也适用。 - 结束说明]; 和 函数f的完成在之前 ([intro.multithread])排序,共享状态准备就绪 。 [注意:f可能根本不会被调用,因此它的完成可能永远不会发生。 - 结束说明] 如果实现选择launch::async策略, 在异步返回 ...相关文章
更多- There is already an open DataReader associated with this Connection which must be closed first
- 项目中用连接池管理Connection,connection用完后还关闭吗?
- The connection to adb is down, and a severe error has occured.
- Hadoop master connection reset by peer resolution
- Cannot expose request attribute 'website' because of an existing model object of the same name 的解决方案
- myEclipse8.5 New DataBase Connection Driver时出错
- httpclient 关闭连接池中无效连接
- JDBC 连接管理
- 安装Hadoop过程中遇到的几个问题
- java连接oracle出错
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)