[搜片神器]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种子文件时生成子文件夹,可能导致有的朋友运行 ...
随机推荐
- web项目的两个创建形式website和webapplication(转)
前言 在利用VS2010创建web项目的时候,会有两个选择.可以选择直接创建website网站,还可以选择使用 webapplication应用程序.刚刚接触web开发,看到这两个就疑惑了,既然是都可 ...
- hdu 3635 Dragon Balls
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- VS中的波浪线
绿色波浪线: 如果你的代码中出现了绿色的波浪线,说明你的代码语法并没有错误, 只不过提示你有可能会出现错误,但是不一定会出现错误.警告线 红色波浪线: 如果你的代码中出现了红色的波浪线,意味着你的代码 ...
- Features for configuring JSON-to-Java mapping
Following on/off features are defined in DeserializationConfig.Feature (Jackson 1.x) or Deserializat ...
- Jersey(1.19.1) - Hello World, Get started with a Web application
1. Maven Dependency <properties> <jersey.version>1.19.1</jersey.version> </prop ...
- django 学习-7 模型数据操作
1.首先还是创建办一个项目和一个应用 django.admin.py startproject ssj cd ssj django.admin.py startapp sdj 那 ...
- C# 计算文件的 Hash 值
/// <summary> /// 提供用于计算指定文件哈希值的方法 /// <example>例如计算文件的MD5值: /// <code> /// String ...
- Android之触屏事件
方法一: 新建"MyView"类 package onTouchEvent; import android.content.Context; import android.grap ...
- Swift结构体与类
在面向过程的编程语言(如C语言)中,结构体用得比较多,但是面向对象之后,如在C++和Objective-C中,结构体已经很少使用了.这是因为结构体能够做的事情,类完全可以取而代之.而Swift语言却非 ...
- OC3_歌词解析
// // LrcManager.h // OC3_歌词解析 // // Created by zhangxueming on 15/6/15. // Copyright (c) 2015年 zhan ...