易截截图软件、单文件、免安装、纯绿色、仅160KB

Socket编程(C#)

//Socket基本编程
//服务端:
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
Thread mythread ;
Socket socket;
// 清理所有正在使用的资源。
protected override void Dispose( bool disposing )
{
try
  {   
   socket.Close();//释放资源
   mythread.Abort ( ) ;//中止线程
  }
  catch{ }
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
public static IPAddress GetServerIP()
{
IPHostEntry ieh=Dns.GetHostByName(Dns.GetHostName());
return ieh.AddressList[0];
}
private void BeginListen()
{
IPAddress ServerIp=GetServerIP();
IPEndPoint iep=new IPEndPoint(ServerIp,8000);
socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
byte[] byteMessage=new byte[100];
this.label1.Text=iep.ToString();
socket.Bind(iep);
// do
while(true)
{
try
{
socket.Listen(5);
Socket newSocket=socket.Accept();
newSocket.Receive(byteMessage);
string sTime = DateTime.Now.ToShortTimeString ( ) ;
string msg=sTime+":"+"Message from:";
msg+=newSocket.RemoteEndPoint.ToString()+Encoding.Default.GetString(byteMessage);
this.listBox1.Items.Add(msg);
}
catch(SocketException ex)
{
this.label1.Text+=ex.ToString();
}
}
// while(byteMessage!=null);
}
//开始监听
private void button1_Click(object sender, System.EventArgs e)
{
try
{
mythread = new Thread(new ThreadStart(BeginListen));
mythread.Start();
}
catch(System.Exception er)
{
MessageBox.Show(er.Message,"完成",MessageBoxButtons.OK,MessageBoxIcon.Stop);
}
}
//客户端:
using System.Net;
using System.Net.Sockets;
using System.Text;
private void button1_Click(object sender, System.EventArgs e)
{
BeginSend();
}
private void BeginSend()
{
string ip=this.txtip.Text;
string port=this.txtport.Text;
IPAddress serverIp=IPAddress.Parse(ip);
int serverPort=Convert.ToInt32(port);
IPEndPoint iep


相关文档:

c# enmu 枚举小结(1)

 
枚举
  枚举类型声明为一组相关的符号常数定义了一个类型名称。枚举用于“多项选择”场合,就是程序运行时从编译时已经设定的固定数目的“选择”中做出决定。
  枚举类型(也称为枚举)为定义一组可以赋给变量的命名整数常量提供了一种有效的方法。例如,假设您必须定义一个变量,该变量 ......

C# 调用 c++ dll 的一些问题总结

1.c++的到处函数只要在函数申明的时候加个导出关键字就可以了
2.参数类型问题,
一般的c++中char * 对应 c#中的string
而c++中 char **类型的参数对应c#中 ref string 这种一般都是用来返回字符串的!
3.函数入口问题,一般会出现 "找不到入口点" 这个问题不是由你引起的,而是系统自己把名字改了,改成什么样的名字建议你用 ......

c# 类库

[SerializableAttribute]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDual)]
public class Object
1 public virtual bool Equels (Object)
2 public static bool static Equels (Object,Object)
默认实现为对引用类型使用引用相等,对值类型使用二进制按位相等。引用相等性是指进 ......

C#实现文件关联

和其他语言一样,C#实现文件关联同样需要直接操作注册表,即按规则分别设置文件扩展名,文档类型说明,友好名称,图标,调用方法等键值即可,网上随便查查就可以写出以下的代码。 using Microsoft.Win32; RegistryKey key = Registry.ClassesRoot.OpenSubKey(".jb");
if (key == null)
{
 ......

C#对图片的几种简单处理

又有一段时间没有更新了,缺少学习的热情了。今天贴几个图片处理的小技巧,希望对大家有用:
(1)如何获取.gif图片中的各个帧?
(2)如何获取图片的缩略图?
(3)如何“截取”图片的指定区域?
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public class ImageHelp ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号