摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data.Common;using System.Data.Linq;using System.Reflection;using System.Linq.Expressions;using System.Collections;using System.Text.RegularExpressions;namespace Rocky.Data{ /// <summary> /// Business
阅读全文
摘要:HTTP隧道是一种通信技术,通过该技术,使用不同的网络协议,使用HTTP协议,网络协议问题通常属于TCP / IP的协议族的封装。HTTP协议,因此,作为一个通道,被传输的网络协议进行通信时使用的包装。HTTP流,其隐蔽通道被称为一个HTTP隧道。HTTP隧道软件由客户端-服务器的HTTP隧道与现有的应用软件集成的应用程序,允许它们被用在条件受限的网络连接,包括防火墙的网络。 HTTP隧道机制:希望与远程主机进行通信的应用程序打开一个HTTP连接到一个中介服务器,充当通信中继和远程主机。然后,应用程序与中介服务器使用HTTP请求,这些请求内封装的实际通信。中介服务器解开前的实际数据转发到...
阅读全文
摘要:更新使用.net 4.0Parallel 来代替 new Thread();/*********************************************************************************** File Name : FileTransmitor.cs** Copyright (C) 2010 Snda Network Corporation. All Rights Reserved.** Creator : RockyWong** Create Date : 2010-06-02 11:22:45...
阅读全文
摘要:string menuShortcut = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), string.Format(@"{0}\{1}.appref-ms", Application.CompanyName, Application.ProductName)); Console.Out.WriteInfo(menuShortcut); string startupShort...
阅读全文
摘要:private Socket GetPushSock(Stream pushStream) { var prop = pushStream.GetType().GetProperty("InternalSocket", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty); return (Socket)prop.GetValue(pushStream, null); }
阅读全文
摘要:/// <summary> /// Expression visitor /// (from http://blogs.msdn.com/mattwar/archive/2007/07/31/linq-building-an-iqueryable-provider-part-ii.aspx) /// </summary> public abstract class ExpressionVisitor { protected ExpressionVisitor() { } protected virtual E...
阅读全文
摘要:var reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (reg.GetValue(_notify.Text) == null) { reg.SetValue(_notify.Text, Application.ExecutablePath); Console.Out.Writ...
阅读全文
摘要: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
阅读全文
摘要: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); ...
阅读全文
摘要:开发互联网应用的过程中,常常会设立或利用网络接口。为了调试对网络接口的使用,往往需要查看流入和流出网络接口的网络流量或数据包。“抓包工具”就是一类用于记录通过网络接口的数据的工具。我们知道,网络协议是分层设计的,OSI模型将网络协议分为了7个层次。不同的抓包工具,可以在网络协议的不同层次上工作。常用的Wireshark就是一种在网络层上工作的抓包工具,不仅自带大量的协议分析器,而且可以通过编写Wireshark插件来识别自定义的协议。虽然Wireshark功能强大,但是却并不能解决所有的抓包问题,其原因在于:Wireshark工作在网络层;如果计算机配置了IPSec传输层加密,则在网络层的流量
阅读全文
摘要:网络读取需要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...
阅读全文