Tag:

在C#中计算来自未知长度的流的哈希

在C#中计算“动态”md5的最佳解决方案是什么,就像未知长度的流的哈希一样? 具体来说,我想根据通过网络收到的数据计算哈希值。 我知道当发件人终止连接时我已收到数据,所以我不知道提前的长度。 [编辑] – 现在我正在使用md5,但这需要在数据保存并写入磁盘后再次传递数据。 当它从网络进入时,我宁愿哈希它。

将输入流式传输到System.Speech.Recognition.SpeechRecognitionEngine

我试图从TCP套接字在C#中进行“流式”语音识别。 我遇到的问题是SpeechRecognitionEngine.SetInputToAudioStream()似乎需要一个可以寻找的定义长度的Stream。 现在,我能想到的唯一方法就是在更多输入进来时在MemoryStream上重复运行识别器。 这里有一些代码来说明: SpeechRecognitionEngine appRecognizer = new SpeechRecognitionEngine(); System.Speech.AudioFormat.SpeechAudioFormatInfo formatInfo = new System.Speech.AudioFormat.SpeechAudioFormatInfo(8000, System.Speech.AudioFormat.AudioBitsPerSample.Sixteen, System.Speech.AudioFormat.AudioChannel.Mono); NetworkStream stream = new NetworkStream(socket,true); appRecognizer.SetInputToAudioStream(stream, formatInfo); // At the line above a “NotSupportedException” complaining that “This stream does not support seek operations.” 有谁知道怎么解决这个问题? 它必须支持某种流输入,因为它使用SetInputToDefaultAudioDevice()与麦克风一起正常工作。 谢谢,肖恩

如何上传文件并将其保存到Stream以便使用C#进一步预览?

有没有办法上传文件,将其保存到Stream,这个Stream我会暂时保存在Session中,最后,我会尝试预览这个Session中的上传文件? 例如,pdf文件。 谢谢!! EDITED 这是我正在尝试做的事情: HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase; byte[] buffer = new byte[hpf.InputStream.Length]; MemoryStream ms = new MemoryStream(buffer); ms.Read(buffer, 0, (int)ms.Length); Session[“pdf”] = ms.ToArray(); ms.Close(); 在另一种方法中,我这样做: byte[] imageByte = null; imageByte = (byte[])Session[“pdf”]; Response.ContentType = “application/pdf”; Response.Buffer = true; Response.Clear(); Response.BinaryWrite(imageByte); 但没有任何事情发生…我的浏览器甚至打开一个nem页面来显示pdf文件,但是会显示一个窗口,说该文件不是pdf(或者文件不是用pdf启动的,我不明白那)

FileUpload到FileStream

我正在与HttpWebRequest一起发送文件。 我的文件将来自FileUpload UI。 在这里,我需要将文件上传转换为文件流,以便与HttpWebRequest一起发送流。 如何将FileUpload转换为文件流?

当我读取500MB FileStream时OutOfMemoryException

我正在使用Filestream读取大文件(> 500 MB),我得到了OutOfMemoryException。 任何解决方案。 我的代码是: using (var fs3 = new FileStream(filePath2, FileMode.Open, FileAccess.Read)) { byte[] b2 = ReadFully(fs3, 1024); } public static byte[] ReadFully(Stream stream, int initialLength) { // If we’ve been passed an unhelpful initial length, just // use 32K. if (initialLength 0) { read += chunk; // If we’ve reached the end of […]

尝试通过它的访问权限以某种方式访问​​套接字forbbiden。 为什么?

private void StartReceivingData(string ipAddress, int iPort) { try { if (!_bContinueReciving) { //initializeMainSocket(ipAddress, iPort); _mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);//<——HERE IS RAISED THE EXCEPTION _mSocket.Bind(new IPEndPoint(IPAddress.Parse(ipAddress), iPort)); // _mSocket.Bind(new IPEndPoint(IPAddress.Loopback, iPort)); _mSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true); _mSocket.IOControl(IOControlCode.ReceiveAll, new byte[4] { 1, 0, 0, 0 }, new byte[4] { 0, 0, 0, 0 }); //var 1 _mSocket.BeginReceive(_buffReceivedData, 0, […]

Console.Read()和Console.ReadLine()之间的区别?

我是这个领域的新手,我很困惑: Console.Read()和Console.ReadLine()之间的真正区别是什么?