我的公告
我的相册
友情链接
最新文章
- SOCKET编程
- ASCII字节数组转换为Unicode字符串
- 非对称加密算法
- 带阴影的时钟
- setTimeout() 方法的返回值
- 数据库实现树结构
- location.search和location.pathname
- 部署windows服务--制作安装包
- C# 程序中调用另一个可执行程序
- 如何实现将远程对象创建为单一实例
- 复杂SQL语句(二)
- 复杂SQL语句(一)
- CSS背景:background-repeat
- 用于引用类型的 ref 参数
- 类和结构的可访问性
- VS2005无法切换到设计视图的解决方案
- 经典程序1——参数方程
- 在 XP HOME 安装 IIS
- 关于 union/union all 和 order by
- 初学javascrpit事件
文章专辑
空白面板
背景音乐
2007-07-21 14:28:30
//client端
using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace socketsample
{
class Class1
{
static void Main()
{
try
{
int port = 2000;
string host = "127.0.0.1";
IPAddress ip = IPAddress.Parse(host);
IPEndPoint ipe = new IPEndPoint(ip, port);//把ip和端口转化为IPEndPoint实例
Socket c = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个Socket
Console.WriteLine("Conneting...");
c.Connect(ipe);//连接到服务器
string sendStr = "hello!This is a socket test";
byte] bs = Encoding.ASCII.GetBytes(sendStr);
Console.WriteLine("Send Message");
c.Send(bs, bs.Length, 0);//发送测试信息
string recvStr = "";
byte] recvBytes = new byte1024];
int bytes;
bytes = c.Receive(recvBytes, recvBytes.Length, 0);//从服务器端接受返回信息
recvStr
using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace socketsample
{
class Class1
{
static void Main()
{
try
{
int port = 2000;
string host = "127.0.0.1";
IPAddress ip = IPAddress.Parse(host);
IPEndPoint ipe = new IPEndPoint(ip, port);//把ip和端口转化为IPEndPoint实例
Socket c = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个Socket
Console.WriteLine("Conneting...");
c.Connect(ipe);//连接到服务器
string sendStr = "hello!This is a socket test";
byte] bs = Encoding.ASCII.GetBytes(sendStr);
Console.WriteLine("Send Message");
c.Send(bs, bs.Length, 0);//发送测试信息
string recvStr = "";
byte] recvBytes = new byte1024];
int bytes;
bytes = c.Receive(recvBytes, recvBytes.Length, 0);//从服务器端接受返回信息
recvStr
2007-06-29 11:21:43
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
namespace Cryptography
{
class Program
{
static void Main(string] args)
{
Program pro = new Program();
pro.StartDemo();
}
public void StartDemo()
{
// RSA的加解密过程:
// 有 rsa1 和 rsa2 两个RSA对象。
// 现在要 rsa2 发送一段信息给 rsa1, 则先由 rsa1 发送“公钥”给 rsa2
// rsa2 获取得公钥之后,用来加密要发送的数据内容。
// rsa1 获取加密了的数据内容后,用自己的私钥解密,得出原始的数据内容。
RSACryptoServiceProvider rsa1 = new RSACryptoServiceProvider();
RSACryptoServiceProvider rsa2 = new RSACryptoServiceProvider();
string publicKey;
publicKey = rsa1.ToXmlString(false);//导出 rsa1 的公钥
rsa2.FromXmlString(publicKey); //rsa2 导入 rsa1 的公钥,用于加密信息
string plainText;
plainText = "你好!这是用于加密解密的测试字符串";
Console.WriteLine("原始数据是:\n{0}\n", plainText);
byte] cipherBytes;
cipherBytes = rsa2.Encrypt(E
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
namespace Cryptography
{
class Program
{
static void Main(string] args)
{
Program pro = new Program();
pro.StartDemo();
}
public void StartDemo()
{
// RSA的加解密过程:
// 有 rsa1 和 rsa2 两个RSA对象。
// 现在要 rsa2 发送一段信息给 rsa1, 则先由 rsa1 发送“公钥”给 rsa2
// rsa2 获取得公钥之后,用来加密要发送的数据内容。
// rsa1 获取加密了的数据内容后,用自己的私钥解密,得出原始的数据内容。
RSACryptoServiceProvider rsa1 = new RSACryptoServiceProvider();
RSACryptoServiceProvider rsa2 = new RSACryptoServiceProvider();
string publicKey;
publicKey = rsa1.ToXmlString(false);//导出 rsa1 的公钥
rsa2.FromXmlString(publicKey); //rsa2 导入 rsa1 的公钥,用于加密信息
string plainText;
plainText = "你好!这是用于加密解密的测试字符串";
Console.WriteLine("原始数据是:\n{0}\n", plainText);
byte] cipherBytes;
cipherBytes = rsa2.Encrypt(E
2007-06-28 21:57:02
<html>
<head>
<title>带阴影的时钟</title>
<style type="text/css">
<!--
.time{
font-family : Comic Sans Ms;
font-size : 18pt;
font-weight : bold;
color: #00008D;
}
-->
</style>
<script Language="JavaScript">
var ctimer;
function init(){
if (document.all){
tim2.style.left=tim1.style.posLeft;
tim2.style.top=tim1.style.posTop+tim1.offsetHeight-6;
settimes();
}
}
function settimes(){
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
if (hours<10)
hours="0"+hours;
if(mins<10)
mins="0"+mins;
if (secs<10)
secs="0"+secs;
tim1.innerHTML=hours+":"+mins+":"+secs
tim2.innerHTML=hours+":"+mins+":"+secs
ctimer=setTimeout('settimes()',960);
}
</script>
</head>
<body onLoad="init()">
<div
<head>
<title>带阴影的时钟</title>
<style type="text/css">
<!--
.time{
font-family : Comic Sans Ms;
font-size : 18pt;
font-weight : bold;
color: #00008D;
}
-->
</style>
<script Language="JavaScript">
var ctimer;
function init(){
if (document.all){
tim2.style.left=tim1.style.posLeft;
tim2.style.top=tim1.style.posTop+tim1.offsetHeight-6;
settimes();
}
}
function settimes(){
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
if (hours<10)
hours="0"+hours;
if(mins<10)
mins="0"+mins;
if (secs<10)
secs="0"+secs;
tim1.innerHTML=hours+":"+mins+":"+secs
tim2.innerHTML=hours+":"+mins+":"+secs
ctimer=setTimeout('settimes()',960);
}
</script>
</head>
<body onLoad="init()">
<div
2007-06-26 13:45:44
http://localhost/test/test.htm?id=1
<html>
<head>
</head>
<body>
<script languge=javascript>
alert(window.location.pathname); --返回 /test/test.htm
alert(window.location.search); --返回 ?id=1
alert(window.location.href); --返回 http://localhost/test/test.htm?id=1
</script>
</body>
</html>
location对象
含有当前URL的信息.
属性
href 整个URL字符串.
protocol 含有URL第一部分的字符串,如http:
host 包含有URL中主机名:端口号部分的字符串.如//www.cenpok.net/server/
hostname 包含URL中主机名的字符串.如http://www.cenpok.net ;
port 包含URL中可能存在的端口号字符串.
pathname URL中"/"以后的部分.如~list/index.htm
hash "#"号(CGI参数)之后的字符串.
search "?"号(CGI参数)之后的字符串.
<html>
<head>
</head>
<body>
<script languge=javascript>
alert(window.location.pathname); --返回 /test/test.htm
alert(window.location.search); --返回 ?id=1
alert(window.location.href); --返回 http://localhost/test/test.htm?id=1
</script>
</body>
</html>
location对象
含有当前URL的信息.
属性
href 整个URL字符串.
protocol 含有URL第一部分的字符串,如http:
host 包含有URL中主机名:端口号部分的字符串.如//www.cenpok.net/server/
hostname 包含URL中主机名的字符串.如http://www.cenpok.net ;
port 包含URL中可能存在的端口号字符串.
pathname URL中"/"以后的部分.如~list/index.htm
hash "#"号(CGI参数)之后的字符串.
search "?"号(CGI参数)之后的字符串.
2007-06-25 11:39:32
(1)、建立一个新的windows服务项目Server1
(2)、打开Service1代码视图,找到OnStart部分,加入代码
(3)、切换到设计视图,右键-添加安装程序
(4)、切换到新生成的ProjectInstaller.cs设计视图,找到serviceProcessInstaller1对Account属性设置为LocalSystem,对serviceInstaller1的ServiceName属性设置为Server1(服务的名字),StartType属性设置为Automatic(系统启动的时候自动启动服务)
(5)、建立一个新的安装项目ServerSetup(我们为刚才那个服务建立一个安装项目)
(6)、右键-添加-项目输出-主输出-选择Service1-确定
(7)、右键-视图-自定义操作-自定义操作上(安装)右键-添加自定义操作-打开应用程序文件夹-选择刚才那个主输出-确定
(7.5).右键-视图-自定义操作-自定义操作上(卸载)右键-添加自定义操作-打开应用程序文件夹-选择刚才那个主输出-确定 -设置(arguments属性='/u' 作为卸载时并卸载服务)
(8)、重新生成这个安装项目-右键-安装
(9)、在服务管理器中(我的电脑-右键-管理-服务和应用程序-服务)找到Server1服务,启动服务
(2)、打开Service1代码视图,找到OnStart部分,加入代码
(3)、切换到设计视图,右键-添加安装程序
(4)、切换到新生成的ProjectInstaller.cs设计视图,找到serviceProcessInstaller1对Account属性设置为LocalSystem,对serviceInstaller1的ServiceName属性设置为Server1(服务的名字),StartType属性设置为Automatic(系统启动的时候自动启动服务)
(5)、建立一个新的安装项目ServerSetup(我们为刚才那个服务建立一个安装项目)
(6)、右键-添加-项目输出-主输出-选择Service1-确定
(7)、右键-视图-自定义操作-自定义操作上(安装)右键-添加自定义操作-打开应用程序文件夹-选择刚才那个主输出-确定
(7.5).右键-视图-自定义操作-自定义操作上(卸载)右键-添加自定义操作-打开应用程序文件夹-选择刚才那个主输出-确定 -设置(arguments属性='/u' 作为卸载时并卸载服务)
(8)、重新生成这个安装项目-右键-安装
(9)、在服务管理器中(我的电脑-右键-管理-服务和应用程序-服务)找到Server1服务,启动服务
2007-06-24 08:35:28
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace CallAnotherExe
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Process proc = new Process();
proc.StartInfo.FileName = @".\Mailer.exe";
proc.StartInfo.Arguments = "";
proc.Start();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace CallAnotherExe
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Process proc = new Process();
proc.StartInfo.FileName = @".\Mailer.exe";
proc.StartInfo.Arguments = "";
proc.Start();
}
}
}
2007-06-18 15:31:01
远程对象类:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
namespace Microsoft.Samples
{
public class HelloServer: MarshalByRefObject
{
private static int mCounter = 0;
public HelloServer()
{
Console.WriteLine("HelloServer activated");
}
public String HelloMethod(String name)
{
Console.WriteLine("Hello.HelloMethod : {0}", name);
return String.Format("Hi there {0}", name);
}
public int CountMe()
{
lock (this)
{
return mCounter++;
}
}
}
}
服务端:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
namespace Microsoft.Samples
{
publ
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
namespace Microsoft.Samples
{
public class HelloServer: MarshalByRefObject
{
private static int mCounter = 0;
public HelloServer()
{
Console.WriteLine("HelloServer activated");
}
public String HelloMethod(String name)
{
Console.WriteLine("Hello.HelloMethod : {0}", name);
return String.Format("Hi there {0}", name);
}
public int CountMe()
{
lock (this)
{
return mCounter++;
}
}
}
}
服务端:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
namespace Microsoft.Samples
{
publ

注释怎么是英文的呢?
我想去

