[搜片神器]BT种子下载超时很多的问题分析
继续接着第一篇写:使用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种子下载超时很多的问题分析的更多相关文章
- [放松一下] 经典高清电影合集 170G BT种子下载
经典高清电影合集 170G BT种子下载 点击文件名下载 经典高清电影合集170G BT种子.torrent 下载方法 经典高清电影合集详情见目录: 1. 杀手47 2. 这个杀手不太冷 3. 放牛班 ...
- [搜片神器]BT管理程序数据库速度调试优化问题
DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr 谢谢园子 ...
- 《刺杀金正恩》1080p全高清无水印,附中文字幕 bt种子下载,附字母(百度网盘/360云盘)
<刺杀金正恩>1080p全高清无水印,附中文字幕下载(百度网盘/360云盘) 种子和字幕下载地址: thunder://QUFlZDJrOi8vfGZpbGV8JUU5JTg3JTg3JU ...
- [搜片神器]直接从DHT网络下载BT种子的方法
DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr DHT系 ...
- [搜片神器]使用C#实现DHT磁力搜索的BT种子后端管理程序+数据库设计(开源)
谢谢园子朋友的支持,已经找到个VPS进行测试,国外的服务器:http://www.sosobta.com 大家可以给提点意见... 出售商业网站代码,万元起,非诚勿扰,谢谢. 联系h31h31 a ...
- Linux使用Aria2命令下载BT种子/磁力/直链文件 转载
Linux使用Aria2命令下载BT种子/磁力/直链文件 博主: Rat's 发布时间:2017 年 10 月 10 日 26725 次浏览 8 条评论 1073 字数 分类:主机教程 首页 正文 分 ...
- 根据hash值找到bt种子的磁力下载链
根据hash值找到bt种子的磁力下载链- 画皮2 hash:E5757D533B3690774519E6A80021E43C03A58C0B 磁力 下载链接 如下: magnet:?xt=urn:bt ...
- PHP语言编写的磁力搜索工具下载BT种子 支持transmission、qBittorrent
磁力搜索网站2020/01/12更新 https://www.cnblogs.com/cilisousuo/p/12099547.html PT种子.BT种子搜索功能 IYUU自动辅种工具,目前能对国 ...
- [C#搜片神器] 之P2P中DHT网络爬虫原理
继续接着上一篇写:使用C#实现DHT磁力搜索的BT种子后端管理程序+数据库设计(开源)[搜片神器] 昨天由于开源的时候没有注意运行环境,直接没有考虑下载BT种子文件时生成子文件夹,可能导致有的朋友运行 ...
随机推荐
- MJViewController的view的创建
- IIS设置允许下载.exe文件解决方法(转)
最近很多客户使用IIS服务器,然后提示返现宝下载无法找到等无法下载的问题. 返现宝是.exe安装文件,部分服务器或主机可能无法下载. 第一.如果是自己服务器或VPS请按如下设置: 1.设置MIME,让 ...
- Linux 解压/压缩操作命令
.tar 解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)———————————————.gz解压1:gun ...
- Git CMD - push: Update remote refs along with associated objects
命令格式 git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pac ...
- Android代码内存优化建议-OnTrimMemory优化
原文 http://androidperformance.com/2015/07/20/Android代码内存优化建议-OnTrimMemory优化/ OnTrimMemory 回调是 Androi ...
- Activity的启动模式(android:launchMode)
在android里,有4种activity的启动模式,分别为: “standard” (默认) “singleTop” “singleTask” “singleInstance” 它们主要有如下不同: ...
- 解析LRC歌词文件readlrc
package com.jikexueyuan.readlrc.main; import com.jikexueyuan.readlrc.utils.Utils; import java.io.Fil ...
- 学习IT技术的技巧
怎样学习一个知识A? (1).为什么需要A? (*) (2).什么是A? (*) (3).怎么使用A[最简答的]? (*) (4).使用A时注意的问题? (*) (5).A的应用领域. (6) ...
- 方法:查询MongoDB数据库中最新一条数据(JAVA)
使用JAVA语言查询MongoDB中某个数据库某个集合的最新一条数据: MongoCollection<Document> cpu = MongoClient.getDatabase(&q ...
- UVALive 6811 Irrigation Line(二分图最小点覆盖--匈牙利算法)
题意:求最少的线可以覆盖一个由0.1两种数字组成的图中所有的1. eg: 只需要两条线即可. 分析: 1.先为上述例子的行列标号 2.若图中数字为1,则代表该数字所在的行与列有关联. 例如第r1行第c ...