继续接着第一篇写:使用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. gitlab ce 中删除空项目之后,没有删除掉,访问500

    在VirtualBox中的gitlab ce,在管理页面的操作如下: 新建一个仓库名为test的仓库,并从gitlab中导入 导入失败,使用root用户登录,在 Admin Area -> Pr ...

  2. BZOJ 2962

    2962: 序列操作 Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 618  Solved: 225[Submit][Status][Discuss] ...

  3. CSS3 媒体记

    css3 媒体 Media Type 媒体类型 媒体类型是CSS2中一个非常有用的属性.通过媒体类型可以对不同的设备指定不同的样式. W3C共列出十种媒体类型,如表: 值 设备类型 all 所有设备 ...

  4. 一段C程序分析

    #include <stdio.h> #include <stdlib.h> void main() { int i; ; char ch; printf("请输入一 ...

  5. JDBC之数据库操作

    JDBC重要界面有: java.sgl.DriverManager:完成驱动程序的装载和建立新的数据库连接. java.sgl.Connection:表示对某一指定数据库的连接. java.sgl.S ...

  6. Session id实现通过Cookie来传输方法及代码参考

    1. Web中的Session指的就是用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏览这个网站所花费的时间.因此从上述的定义中我们可以看到,Session实际上是一个特定的 ...

  7. (转)Hessian(C#)介绍及使用说明

    什么是Hessian? Hessian是Caucho开发的一种二进制Web Service协议.支持目前所有流行的开发平台. Hessia能干什么? hessian用来实现web服务. Hessia有 ...

  8. 对JavaScript莫名的愤怒

    很多时候,我都察觉JavaScript有一中描述性语言的特性,为了实现他的功能,在浏览器中完美的发挥作用,他就像是一个巨型的工厂工程模式,外挂了很多API和功能集,他们试图用完美的方案去解释所有必须的 ...

  9. tinyMCE自定义添加图片插件

    需求: 在富文本编辑器中插入图片,图片来自用户可以自己上传的图片库. 本来可以用比较恶心的方式,也就是直接用tinyMCE自带的插入图片插件来实现.恶心是因为这个图片插件需要用户填入图片的url. 想 ...

  10. Linux进程调度

    原文地址: http://cchxm1978.blog.163.com/blog/static/35428253201092910491682/ 相当不错的文章,读了后收藏,多谢博主分享! ----- ...