摘要:using System;using System.Collections.Generic;using System.Collections.Specialized;using System.Diagnostics.Contracts;using System.IO;using System.Linq;using System.Net;using System.Text;namespace Rocky.Net{ public sealed class HttpRequestWrapper : System.Web.HttpRequestBase { internal ...
阅读全文
摘要:IntroductionAn application deployed using ClickOnce may not receive an upgrade if the browser's proxy server has cached an older deployment file. This article explains how to solve this problem using HTTP content expiration.BackgroundLet's assume you have deployed an application, called Test
阅读全文
摘要:为什么要用非门,有什么好处? 1. 突破防火墙限制,例如mstsc远程桌面、Redis通信等端口; 2. 突破只能通过代理服务器上网的限制,这样就会使其它直接代理的方式失效;BTW,非门的代理方式不会受影响; 3.支持 socks4/4a/5、Http(s) 代理协议; 4. 并支持multiple tunnels,能与Web服务共享80端口; 5.优化迅雷等P2P软件的通讯; 6.Http(s) 代理协议可翻G#F#W; 7. 可与proxifier、sockcap等软件整合使用,实现路由功能;内测安装地址:http://publish.xineworld.com/clouda...
阅读全文
摘要:private HttpListener _httpListener;private HttpTunnelClient(ushort listenPort, Uri serverUri, NetworkCredential credential, IPEndPoint remoteEndPoint = null, SocksProxyType? runType = null) {_httpListener = new HttpListener(); _httpListener.Prefixes.Add(string.Format("http://*:...
阅读全文
摘要:public static void SetBytes(this byte[] instance, int offset, long value) { Contract.Requires(instance != null); instance[offset++] = (byte)value; instance[offset++] = (byte)(value >> 8); instance[offset++] = (byte)(value >> 0x10); ...
阅读全文
摘要:网络读取需要buffer, 就是byte[]数组啦。buffer分配后占用固定内存,size设小了不够用,size设大了造成浪费并且频繁创建对性能有影响; 需要对buffer进行复用,目前了解有2种方式:1.buffer对象池,WCF就用的此方式;2.buffer分割,即ArraySegment<byte>; 无论是上面那种方式,在调用的时候均需要关注buffer,像数组分割还要关心offset等很麻烦。如:byte[] buffer = new byte[512]; Stream stream = new MemoryStream(); s...
阅读全文
摘要:public static bool IsBase64(string input) { return (input.Length % 4) == 0 && Regex.IsMatch(input, "^[A-Z0-9/+=]*$", RegexOptions.IgnoreCase); } public static string Base64Encode(string input) { return Convert.ToBase64String(Encoding.UTF8.Get...
阅读全文
摘要:针对目前防火墙的一些情况,如果自己的进程开一个端口(甚至是新建套接字)肯定被拦.相反,有一点我们也很清楚:被防火墙验证的进程在传送数据时永远不会被拦.所以,我的思路很简单:将其他进程中允许数据传输的套接字句柄拿为已用.过程如下:1. 找出目标进程2. 找出SOCKET句柄2. 用DuplicateHandle()函数将其SOCKET转换为能被自己使用.3. 用转换后的SOCKET进行数据传输上面的过程写的很简单,但是实际实现起来还是存在一些问题(后面再做讨论).而且从上面的实现方法也可以看出一些不爽的地方:在目标进程的SOCKET不能是TCP,因为TCP的句柄已经跟外面建立了连接,所以只能..
阅读全文
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics.Contracts;using System.Collections.Concurrent;using System.Net;using System.Net.Sockets;using System.IO;namespace Rocky.Net{ public class AsyncTcpListener { #region Fields p...
阅读全文
摘要:using System;using System.Collections.Generic;using System.Diagnostics.Contracts;using System.Linq;using System.Text;using System.IO;namespace Rocky.Net{ [ContractClass(typeof(IPacketsContract))] public interface IPackets { long ContentLength { get; } int? BufferSize { get; se...
阅读全文
摘要:由于我是个粗人,是个菜鸟,只会讲大白话,只想知道咱老百姓想听的内容。不知道为什么那些网文作者都说socks代理比http代理复杂,http代理和socks代理我都做了,明显感觉http代理比socks代理要复杂很多,因为http代理要自己解析http协议,这是我的http代理http://blog.csdn.net/laotse/archive/2010/09/24/5903651.aspx而socks代理除了开头那一点点外,其他就是什么不管就转发转发就行了。我做的那个http代理可谓很失败,用着用着就cpu100%占用了,应该就是解析http协议头做的不好,出现死循环了或者别的,那么多htt
阅读全文
摘要:public static IEnumerable<T> AsEnumerable<T>(this ArraySegment<T> instance) { int length = instance.Offset + instance.Count; for (int i = instance.Offset; i < length; i++) { yield return instance.Array[i]; } }
阅读全文
摘要:用C#下的Raw Socket编程实现网络封包监视谈起socket编程,大家也许会想起QQ和IE,没错。还有许多网络工具如P2P、NetMeeting等在应用层实现的应用程序,也是用socket来实现的。Socket是一个网络编程接口,实现于网络应用层,Windows Socket包括了一套系统组件,充分利用了Microsoft Windows 消息驱动的特点。Socket规范1.1版是在1993年1月发行的,并广泛用于此后出现的Windows9x操作系统中。Socket规范2.2版(其在Windows平台上的版本是Winsock2.2,也叫Winsock2)在 1996 年 5 月发行,Wi
阅读全文
摘要:http://weblogs.asp.net/pwelter34/archive/2011/11/29/entity-framework-batch-update-and-future-queries.aspxBatch Update and DeleteA current limitations of the Entity Framework is that in order to update or delete an entity you have to first retrieve it into memory. Now in most scenarios this is just f
阅读全文
摘要:P2P 之 UDP穿透NAT的原理与实现(附源代码)原创:shootingstars参考:http://midcom-p2p.sourceforge.net/draft-ford-midcom-p2p-01.txt论坛上经常有对P2P原理的讨论,但是讨论归讨论,很少有实质的东西产生(源代码)。呵呵,在这里我就用自己实现的一个源代码来说明UDP穿越NAT的原理。首先先介绍一些基本概念: NAT(Network Address Translators),网络地址转换:网络地址转换是在IP地址日益缺乏的情况下产生的,它的主要目的就是为了能够地址重用。NAT分为两大类,基本的NAT和NAPT(N...
阅读全文
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics.Contracts;using System.Collections.Specialized;using System.IO;using System.Net;using System.Net.Sockets;using System.Net.Security;using System.Net.Mime;using System.Reflection;namespace Rocky.
阅读全文
摘要:public interface IDbSchema { IDbTableSchema[] GetSchema(); } public interface IDbTableSchema { string Name { get; } IDbColumnSchema[] Columns { get; } } public interface IDbColumnSchema { int Ordinal { get; } string Name { get; } boo...
阅读全文
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ComponentModel;using System.Threading;using System.IO;using Rocky;namespace Rocky.CodeBuilder{ public class DbBuilder : Disposable { #region 字段 public event EventHandler DoWork; ...
阅读全文
摘要:using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Reflection.Emit;using System.Runtime.CompilerServices;using System.Text;namespace Rocky{ internal delegate bool Forwarder(WeakReference weakRef, object sender, EventArgs e...
阅读全文
摘要:/// <summary> /// System.Security.SecurityElement.Escape(); /// </summary> /// <param name="xml"></param> /// <returns></returns> public static string GetSafeXml(string xml) { //s = <You're angle & evil>, ['&<>] return Regex.R
阅读全文