摘要: 今天我们来学 socket 发送结构体1. 先看要发送的结构体代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Runtime.InteropServices;namespaceLin.p2p.Mo{///<summary>///通信消息格式///</summary>[Se 阅读全文
posted @ 2010-05-28 17:55 一浩瀚星空一 阅读(2334) 评论(0) 推荐(1) 编辑
摘要: 今天来写一个UPD1.服务端:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Net.Sockets;usingSystem.Net;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){//1.创建套节字S 阅读全文
posted @ 2010-05-27 21:50 一浩瀚星空一 阅读(555) 评论(0) 推荐(1) 编辑
摘要: 现在来传一个图片看看, 改改程序, 看看服务端图片为 140K, 1.jgp1. 服务端代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Text;4usingSystem.Net.Sockets;5usingSystem.Net;6usingSystem.IO;78namespaceConsoleApplication19 阅读全文
posted @ 2010-05-26 22:48 一浩瀚星空一 阅读(387) 评论(0) 推荐(1) 编辑
摘要: 1. 服务端程序Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Text;4usingSystem.Net.Sockets;5usingSystem.Net;67namespaceConsoleApplication18{9classProgram10{11staticvoidMain(string[]args)12{13// 阅读全文
posted @ 2010-05-26 21:15 一浩瀚星空一 阅读(519) 评论(0) 推荐(0) 编辑
摘要: 最近看到一个帖子,问的是怎么把自己定义的结构体转换成对应的byte数组,一般来说,都会想到用Marshal类来完成这个功能,其实还有一个方法也可以,那就是利用unsafe代码。 先定义假想的一个值类型: 然后,定义一个公用方法签名:Action<MyStruct, Stream>,这个是为了方便之后 阅读全文
posted @ 2010-05-25 17:03 一浩瀚星空一 阅读(513) 评论(0) 推荐(0) 编辑
摘要: 最近在用C#做一个项目的时候,Socket发送消息的时候遇到了服务端需要接收C++结构体的二进制数据流,这个时候就需要用C#仿照C++的结构体做出一个结构来,然后将其转换成二进制流进行发送,之后将响应消息的二进制数据流转换成C#结构。1、仿照C++结构体写出C#的结构来 using System.Runtime.InteropServices; [Serializable] // 指示可序列化 [StructLayout(LayoutKind.Sequential, Pack = 1)] // 按1字节对齐 public struct Operator { public ushort id; 阅读全文
posted @ 2010-05-25 10:20 一浩瀚星空一 阅读(489) 评论(0) 推荐(0) 编辑
摘要: [assembly: AssemblyVersion("1.0.0.3")] <!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlig 阅读全文
posted @ 2010-03-27 15:19 一浩瀚星空一 阅读(234) 评论(0) 推荐(0) 编辑
摘要: 通过重写 ProcessCmdKey 方法 <!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br / 阅读全文
posted @ 2009-10-08 11:45 一浩瀚星空一 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 有时在开发程序的时候, 有时需要只能同时运行一个实例.Mutex 类, 称为互拆体, 是一个同步基元, 它只向一个线程授予对共享资源的独占访问权。当两个或更多线程需要同时访问一个共享资源时,系统需要使用同步机制来确保一次只有一个线程使用该资源。如果一个线程获取了互斥体,则要获取该互斥体的第二个线程将 阅读全文
posted @ 2009-10-06 11:16 一浩瀚星空一 阅读(196) 评论(0) 推荐(0) 编辑
摘要: Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1using System; 2 3namespace 算法 4{ 5 /**//// 6 /// 排序 7 /// 8 public static clas... 阅读全文
posted @ 2009-06-21 10:49 一浩瀚星空一 阅读(162) 评论(0) 推荐(0) 编辑