System.Text.Encoding是否异步运行? [英] System.Text.Encoding runs Asynchronous?

查看:125
本文介绍了System.Text.Encoding是否异步运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近研究了一个小型EPP客户端,该客户端是基于TCP/IP的通信协议,使用XML数据包交换命令和响应.我正在使用的服务器专门使用SSL,因此代码包含对SSLStream的引用, 证书和密码短语-请不要让我发布比我在此处提供的代码更多的代码.

I recently worked on a small-scale EPP Client, which is a communications protocol over TCP/IP using XML packets to exchange commands and responses.  The server I'm working with specifically is employing SSL so the code contains references to an SSLStream, certificates and passphrases - please don't ask me to post more code than I provide here.

我们正在原始System.Strings中构建XML EPP命令,然后在字符串上使用System.Text.Encoding.UTF8.GetBytes填充字节数组,然后将字节数组写入SSLStream.服务器将进行通信,协商证书,并 适当地对TLS进行身份验证,但是当我们通过SSLStream发送数据时,服务器根本不会响应发送给它的命令.

We're building the XML EPP Commands in raw System.Strings, then using System.Text.Encoding.UTF8.GetBytes on the string to populate a Byte Array, then writing the Byte Array into the SSLStream.  The server would communicate, negotiate certificates, and authenticate TLS appropriately but when we sent the data over the SSLStream the server simply never responded to the commands sent to it.

我花了好几个小时进行故障排除,然后才打算确定我的客户的证书没有给予他必要的特权,或者服务器主机使用的是不符合RFC的EPP命令格式.为了有足够的证据 为了向我的客户展示此信息,我在几行代码之间插入了一些消息框,以记录对象状态;一个消息框出现在System.Text.Encoding操作之后,等待了足够长的时间让我阅读该消息框, 单击确定",我得到了预期的服务器响应.需要花一两个小时的时间才能弄清楚哪个消息框导致了它的工作,最终我不得不在System.Text.Encoding.UTF8.GetBytes操作之后插入一个线程休眠, 在将字节数组推入流之前.

I worked at troubleshooting this for several hours and was just about to decide either my client's certificate didn't give him necessary privileges or else the server host was using a non-RFC-compliant EPP Command format.  In order to have enough evidence to present this information to my client I stuck some messageboxes in between a few lines of code to take notes on object states; one messagebox occurred right after the System.Text.Encoding operation and with a wait long enough for me to read the box and click OK, I got back a server response as expected.  It took another hour or two of work to figure out which messagebox was causing it to work, and I ultimately had to insert a threadsleep right after the System.Text.Encoding.UTF8.GetBytes operation, before the byte array is pushed into the stream.

Dim EPP_Handshake As System.String = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & " standalone=" & Chr(34) & "no" & Chr(34) & "?>" & _
                         "<epp xmlns=" & Chr(34) & "urn:ietf:params:xml:ns:epp-1.0" & Chr(34) & _
                         " xmlns:xsi=" & Chr(34) & "http://www.w3.org/2001/XMLSchema-instance" & Chr(34) & _
                         " xsi:schemaLocation=" & Chr(34) & "urn:ietf:params:xml:ns:epp-1.0 " & _
                         " epp-1.0.xsd" & Chr(34) & ">" & _
                         " <hello/>" & _
                         "</epp>"


Dim sendBytes() As Byte = System.Text.Encoding.UTF8.GetBytes(EPP_Handshake)
System.Threading.Thread.Sleep(System.TimeSpan.FromMilliseconds(500))

SSLStream.Write(sendBytes, 0, sendBytes.Length)

我以不同的延迟因子来回避,发现在代码工作并且服务器适当响应之前,绝对最小线程休眠为400ms;显然,System.Text.Encoding操作需要很长时间才能完成,并且 操作不会阻塞线程.

I monkeyed around with different delay factors and found that the absolute minimum threadsleep before the code works and the server responds appropriately is 400ms; apparently it takes that long for the System.Text.Encoding operation to complete and the operation isn't blocking the thread.

推荐答案

安德鲁,

我当然不知道答案是什么,但我想说嗨".很高兴再次见到你. :)

Of course I have NO idea what the answer is, but I wanted to say "hi" and that it's good to see you around again. :)


这篇关于System.Text.Encoding是否异步运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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