继续接着第一篇写:使用C#实现DHT磁力搜索的BT种子后端管理程序+数据库设计(开源)[搜片神器]

谢谢园子朋友的支持,已经找到个VPS进行测试,国外的服务器: h31bt.org  大家可以给提点意见...

开源地址:https://github.com/h31h31/H31DHTMgr

程序下载:H31DHT下载

下载种子文件的时候失败很多,增加调试信息总是返回很多:Timeouts are not supported on this stream.

The remote server returned an error: (404) Not Found.

The operation has timed out.

附上之前的代码:

        private int DownLoadFileToSaveFile(string strURL, string fileName)
{
Int32 ticktime1 = System.Environment.TickCount;
try
{
Int32 ticktime2 = ;
byte[] buffer = new byte[]; WebRequest wr = WebRequest.Create(strURL);
wr.ContentType = "application/x-bittorrent";
wr.Timeout = ;
WebResponse response = wr.GetResponse();
int readsize = ;
{
bool gzip = response.Headers["Content-Encoding"] == "gzip";
Stream responseStream = gzip ? new GZipStream(response.GetResponseStream(), CompressionMode.Decompress) : response.GetResponseStream(); using (MemoryStream memoryStream = new MemoryStream())
{
responseStream.ReadTimeout = ;
int count = ;
do
{
count = responseStream.Read(buffer, , buffer.Length);
memoryStream.Write(buffer, , count);
readsize += count;
Thread.Sleep();
} while (count != );
ticktime2 = System.Environment.TickCount; byte[] result = memoryStream.ToArray();
Thread.Sleep();
using (BinaryWriter writer = new BinaryWriter(new FileStream(fileName, FileMode.Create)))
{
writer.Write(result);
}
}
Int32 ticktime3 = System.Environment.TickCount;
//H31Debug.PrintLn("下载成功" + strURL + ":" + readsize.ToString() + ":" + (ticktime2 - ticktime1).ToString() + "-" + (ticktime3 - ticktime2).ToString());
}
return ;
}
catch (Exception e)
{
Int32 ticktime3 = System.Environment.TickCount;
//H31Debug.PrintLn("下载失败" + strURL + ":" + (ticktime3 - ticktime1).ToString());
return -;
}
}

测试在国内服务器上情况很少时间,一放到国外服务器上就出现此问题,网上搜索资料最终显示是

参考1:http://stackoverflow.com/questions/9791423/httpwebresponse-readtimeout-timeouts-not-supported

经过代码分析,原来Stream responseStream里面使用的TIMEOUT参数设置.

                    Stream responseStream = gzip ? new GZipStream(response.GetResponseStream(), CompressionMode.Decompress) : response.GetResponseStream();

                    using (MemoryStream memoryStream = new MemoryStream())
{
responseStream.ReadTimeout = 1000;
int count = ;
do
{
count = responseStream.Read(buffer, , buffer.Length);
memoryStream.Write(buffer, , count);
readsize += count;
Thread.Sleep();
} while (count != );
ticktime2 = System.Environment.TickCount; byte[] result = memoryStream.ToArray();
Thread.Sleep();
using (BinaryWriter writer = new BinaryWriter(new FileStream(fileName, FileMode.Create)))
{
writer.Write(result);
}
}

然后为了防止程序界面卡住,错误的增加了Thread.Sleep(1);其它问题可能就出现在此地方,由于设置超时,然后数据流就被超时退出,从而被系统认为Stream没有注销导致异常,从而显示Timeouts are not supported on this stream.

修改后的代码为:

        private int DownLoadFileToSaveFile(string strURL, string fileName,int timeout1)
{
Int32 ticktime1 = System.Environment.TickCount;
try
{
Int32 ticktime2 = ;
byte[] buffer = new byte[]; WebRequest wr = WebRequest.Create(strURL);
wr.ContentType = "application/x-bittorrent";
wr.Timeout = timeout1;
WebResponse response = wr.GetResponse();
int readsize = ;
{
bool gzip = response.Headers["Content-Encoding"] == "gzip";
Stream responseStream = gzip ? new GZipStream(response.GetResponseStream(), CompressionMode.Decompress) : response.GetResponseStream(); using (MemoryStream memoryStream = new MemoryStream())
{
int count = ;
do
{
count = responseStream.Read(buffer, , buffer.Length);
memoryStream.Write(buffer, , count);
readsize += count;
} while (count != );
ticktime2 = System.Environment.TickCount; byte[] result = memoryStream.ToArray();
Thread.Sleep();
using (BinaryWriter writer = new BinaryWriter(new FileStream(fileName, FileMode.Create)))
{
writer.Write(result);
}
}
Int32 ticktime3 = System.Environment.TickCount;
//H31Debug.PrintLn("下载成功" + strURL + ":" + readsize.ToString() + ":" + (ticktime2 - ticktime1).ToString() + "-" + (ticktime3 - ticktime2).ToString());
}
return ;
}
catch (WebException e)
{
Int32 ticktime3 = System.Environment.TickCount;
if (e.Status == WebExceptionStatus.Timeout)//文件超时
{
return -;
}
else if (e.Status == WebExceptionStatus.ProtocolError)//文件不存在
{
return -;
}
else
{
H31Debug.PrintLn("下载失败" + strURL + ":" + (ticktime3 - ticktime1).ToString() + e.Status.ToString() + e.Message);
return -;
}
}
}

测试程序后出现下载失败的HASH文件少了很多.

The remote server returned an error: (404) Not Found. 此问题是服务器没有此文件,可以采用if (e.Status == WebExceptionStatus.ProtocolError)来判断

The operation has timed out.   此问题是时间不够,可以增加                wr.Timeout = 300;这个时间的问题.

特此记录一下,希望大家多指教..大家可以从开源地址:https://github.com/h31h31/H31DHTMgr下载代码一起交流下..

大家觉得好的话,希望推荐支持下...

[搜片神器]BT种子下载超时很多的问题分析的更多相关文章

  1. [放松一下] 经典高清电影合集 170G BT种子下载

    经典高清电影合集 170G BT种子下载 点击文件名下载 经典高清电影合集170G BT种子.torrent 下载方法 经典高清电影合集详情见目录: 1. 杀手47 2. 这个杀手不太冷 3. 放牛班 ...

  2. [搜片神器]BT管理程序数据库速度调试优化问题

    DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr 谢谢园子 ...

  3. 《刺杀金正恩》1080p全高清无水印,附中文字幕 bt种子下载,附字母(百度网盘/360云盘)

    <刺杀金正恩>1080p全高清无水印,附中文字幕下载(百度网盘/360云盘) 种子和字幕下载地址: thunder://QUFlZDJrOi8vfGZpbGV8JUU5JTg3JTg3JU ...

  4. [搜片神器]直接从DHT网络下载BT种子的方法

    DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr DHT系 ...

  5. [搜片神器]使用C#实现DHT磁力搜索的BT种子后端管理程序+数据库设计(开源)

    谢谢园子朋友的支持,已经找到个VPS进行测试,国外的服务器:http://www.sosobta.com   大家可以给提点意见... 出售商业网站代码,万元起,非诚勿扰,谢谢. 联系h31h31 a ...

  6. Linux使用Aria2命令下载BT种子/磁力/直链文件 转载

    Linux使用Aria2命令下载BT种子/磁力/直链文件 博主: Rat's 发布时间:2017 年 10 月 10 日 26725 次浏览 8 条评论 1073 字数 分类:主机教程 首页 正文 分 ...

  7. 根据hash值找到bt种子的磁力下载链

    根据hash值找到bt种子的磁力下载链- 画皮2 hash:E5757D533B3690774519E6A80021E43C03A58C0B 磁力 下载链接 如下: magnet:?xt=urn:bt ...

  8. PHP语言编写的磁力搜索工具下载BT种子 支持transmission、qBittorrent

    磁力搜索网站2020/01/12更新 https://www.cnblogs.com/cilisousuo/p/12099547.html PT种子.BT种子搜索功能 IYUU自动辅种工具,目前能对国 ...

  9. [C#搜片神器] 之P2P中DHT网络爬虫原理

    继续接着上一篇写:使用C#实现DHT磁力搜索的BT种子后端管理程序+数据库设计(开源)[搜片神器] 昨天由于开源的时候没有注意运行环境,直接没有考虑下载BT种子文件时生成子文件夹,可能导致有的朋友运行 ...

随机推荐

  1. AutoCAD 2014 win 32bit破解版

    AutoCAD 2014 win 32bit破解版 百度云盘:http://pan.baidu.com/s/1nu2u6Hr

  2. css图片映射

    a <div class="imagemap"> <img src="img/map.png" width="496px" ...

  3. Red Hat Enterprise Linux 5安装序列号

    为了保证安装的组件和订阅相匹配,红帽企业 Linux 5 需要输入一个安装号.它被用来配置安装程序来提供正确的软件包.安装号码包含在你的订阅里. 如果您没有输入安装号码,只有核心服务器或 Deskto ...

  4. 随笔001:Group by 语法剪辑

    基本语法: GROUP BY [ALL] group_by_expression[,……n][WITH (CUBE|ROLLUP)] 参数说明: ALL:用于指定包含所有组和结果集,甚至包含那些其中任 ...

  5. Agile.Net 组件式开发平台 - 数据报表组件

    Agile.Report.dll 文件为平台数据报表支持库,基于FasstReport.Net扩展重写,提供了非常强大的自定义报表的功能使开发者为应用程序快速有效地生成报表.报表类库提供了创建报表所需 ...

  6. Java 源码学习线路————_先JDK工具包集合_再core包,也就是String、StringBuffer等_Java IO类库

    http://www.iteye.com/topic/1113732 原则网址 Java源码初接触 如果你进行过一年左右的开发,喜欢用eclipse的debug功能.好了,你现在就有阅读源码的技术基础 ...

  7. mysql 打包表在phpmyadmin提示正在使用中..

    一,利用phpmyadmin修改表功能,REPAIR TABLE `你的表名` 或直接在数据库管理界面,选中表如下图 二,如果利用修改功能失败了我们还可以尝试在替换本地mysql数据库时,我们先停止m ...

  8. Cocos2d-x中Vector<T>容器以及实例介绍

    Vector<T> 是Cocos2d-x 3.x推出的列表容器,因此它所能容纳的是Ref及子类所创建的对象指针,其中的T是模板,表示能够放入到容器中的类型,在Cocos2d-x 3.x中T ...

  9. Cocos2d-x中使用音频CocosDenshion引擎介绍与音频文件的预处理

    Cocos2d-x提供了一个音频CocosDenshion引擎,CocosDenshion引擎可以独立于Cocos2d-x单独使用,CocosDenshion引擎本质上封装了OpenAL音频处理库.具 ...

  10. des算法的C#实现

    DES是Data Encryption Standard(数据加密标准)的缩写.它是一种通过56位密钥来加密64位数据的方法. public class EncryptUtility{    #reg ...