??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美大香线蕉线伊人久久,伊人丁香狠狠色综合久久,久久精品麻豆日日躁夜夜躁http://www.shnenglu.com/Lee7/ 当华的叶片落尽Q生命的脉络才历历可见?Q- 聂鲁? zh-cnWed, 07 May 2025 19:28:49 GMTWed, 07 May 2025 19:28:49 GMT60ZC#的Socket开发快速入?/title><link>http://www.shnenglu.com/Lee7/archive/2009/11/30/102299.html</link><dc:creator>isabc</dc:creator><author>isabc</author><pubDate>Mon, 30 Nov 2009 11:17:00 GMT</pubDate><guid>http://www.shnenglu.com/Lee7/archive/2009/11/30/102299.html</guid><wfw:comment>http://www.shnenglu.com/Lee7/comments/102299.html</wfw:comment><comments>http://www.shnenglu.com/Lee7/archive/2009/11/30/102299.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Lee7/comments/commentRss/102299.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Lee7/services/trackbacks/102299.html</trackback:ping><description><![CDATA[<p>首先从原理上解释一下采用Socket接口的网l通讯Q这里以最常用的C/S模式作ؓ范例Q首先,服务端有一个进E(或多个进E)在指定的端口{待客户?q接Q服务程序等待客Lq接信息Q一旦连接上之后Q就可以按设计的数据交换Ҏ和格式进行数据传输。客L在需要的时刻发出向服务端的连接请求。这里ؓ 了便于理解,提到了一些调用及其大致的功能。用socket调用后,仅生了一个可以用的socket描述W,q时q不能进行通信Q还要用其他的?用,以得socket所指的l构中用的信息被填写完?/p> <p>  在用TCP协议Ӟ一般服务端q程先用socket调用得到一个描q?W,然后使用bind调用一个名字与socket描述W连接v来,对于Internet域就是将Internet地址联编到socket。之后,服务?使用listen调用指出{待服务h队列的长度。然后就可以使用accept调用{待客户端发赯接,一般是d{待q接Q一旦有客户端发接, acceptq回客户的地址信息Qƈq回一个新的socket描述W,该描q符与原先的socket有相同的Ҏ,q时服务端就可以使用q个新的 socketq行d操作了。一般服务端可能在acceptq回后创Z个新的进E进行与客户的通信Q父q程则再到accept调用处等待另一个连接。客 Lq程一般先使用socket调用得到一个socket描述W,然后使用connect向指定的服务器上的指定端口发赯接,一旦连接成功返回,p?已经建立了与服务器的q接Q这时就可以通过socket描述W进行读写操作了?/p> <p>  .NetFrameWork为Socket通讯提供了System.Net.Socket命名I间Q在q个命名I间里面有以下几个常用的重要cd别是:</p> <p>  ·Socketc?q个低层的类用于理q接QWebRequestQTcpClient和UdpClient在内部用这个类?/p> <p>  ·NetworkStreamc?q个cL从Streamz出来的,它表C来自网l的数据?/p> <p>  ·TcpClientc?允许创徏和用TCPq接</p> <p>  ·TcpListenerc?允许监听传入的TCPq接h</p> <p>  ·UdpClientc?用于UDP客户创徏q接(UDP是另外一UTCP协议Q但没有得到q泛的用,主要用于本地|络)</p> <p>  下面我们来看一个基于Socket的双机通信代码的C#版本</p> <p>  首先创徏Socket对象的实例,q可以通过Socketcȝ构造方法来实现Q?/p> <p>public Socket(AddressFamily addressFamily,SocketType socketType,ProtocolType protocolType);  </p> <p>  其中QaddressFamily 参数指定 Socket 使用的寻址ҎQsocketType 参数指定 Socket 的类型,protocolType 参数指定 Socket 使用的协议?</p> <p>  下面的示例语句创Z?SocketQ它可用于在Z TCP/IP 的网l(?InternetQ上通讯?/p> <p>Socket temp = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);  </p> <p>  若要使用 UDP 而不?TCPQ需要更改协议类型,如下面的CZ所C: </p> <p>Socket temp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);  </p> <p>   一旦创?SocketQ在客户端,你将可以通过ConnectҎq接到指定的服务器(你可以在ConnectҎ前Bind端口Q就是以指定的端?发vq接Q如果不事先Bind端口L话,pȝ会默认在1024?000随机l定一个端口号Q,q过SendҎ向远E服务器发送数据,而后可以通过 Receive从服务端接收数据Q而在服务器端Q你需要用BindҎl定所指定的接口Socket与一个本地终l点相联Qƈ通过ListenҎ?听该接口上的hQ当侦听到用L的连接时Q调用Accept完成q接的操作,创徏新的Socket以处理传入的q接h。用完 Socket 后,??Close Ҏ关闭 Socket?</p> <p>  可以看出Q以上许多方法包含EndPointcd的参敎ͼ在Internet中, TCP/IP 使用一个网l地址和一个服务端口号来唯一标识讑֤。网l地址标识|络上的特定讑֤Q端口号标识要连接到的该讑֤上的特定服务。网l地址和服 务端口的l合UCؓl结点,?.NET 框架中正是由 EndPoint c表C个终l点Q它提供表示|络资源或服务的抽象Q用以标志网l地址{信 息?Net同时也ؓ每个受支持的地址族定义了 EndPoint 的子代;对于 IP 地址族,该类?IPEndPoint。IPEndPoint  cd含应用程序连接到L上的服务所需的主机和端口信息Q通过l合服务的主机IP地址和端口号QIPEndPoint cdŞ成到服务的连接点?/p> <p>  用到IPEndPointcȝ时候就不可避免地涉及到计算机IP地址QSystem.Net命名I间中有两种cd以得到IP地址实例Q?</p> <p>  ·IPAddressc:IPAddress cd含计机?IP |络上的地址。其ParseҎ可将 IP 地址字符串{换ؓ IPAddress 实例。下面的语句创徏一?IPAddress 实例Q?</p> <p>IPAddress myIP = IPAddress.Parse("192.168.0.1");  </p> <p>   需要知道的是:Socket cL持两U基本模式:同步和异步。其区别在于Q在同步模式中,按块传输Q对执行|络操作的函敎ͼ?Send ?nbsp; ReceiveQ的调用一直等到所有内容传送操作完成后才将控制q回l调用程序。在异步模式中,是按位传输,需要指定发送的开始和l束。同步模式是最?用的模式Q我们这里的例子也是使用同步模式?/p> <p>// 客户?/p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.Collections.Generic;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.Text;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.IO;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.Net;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.Net.Sockets;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> ClientDemo<br><img id=Codehighlighter1_150_1551_Open_Image onclick="this.style.display='none'; Codehighlighter1_150_1551_Open_Text.style.display='none'; Codehighlighter1_150_1551_Closed_Image.style.display='inline'; Codehighlighter1_150_1551_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_150_1551_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_150_1551_Closed_Text.style.display='none'; Codehighlighter1_150_1551_Open_Image.style.display='inline'; Codehighlighter1_150_1551_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_150_1551_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_150_1551_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> Program<br><img id=Codehighlighter1_174_1549_Open_Image onclick="this.style.display='none'; Codehighlighter1_174_1549_Open_Text.style.display='none'; Codehighlighter1_174_1549_Closed_Image.style.display='inline'; Codehighlighter1_174_1549_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_174_1549_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_174_1549_Closed_Text.style.display='none'; Codehighlighter1_174_1549_Open_Image.style.display='inline'; Codehighlighter1_174_1549_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_174_1549_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_174_1549_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Main(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">[] args)<br><img id=Codehighlighter1_224_1543_Open_Image onclick="this.style.display='none'; Codehighlighter1_224_1543_Open_Text.style.display='none'; Codehighlighter1_224_1543_Closed_Image.style.display='inline'; Codehighlighter1_224_1543_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_224_1543_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_224_1543_Closed_Text.style.display='none'; Codehighlighter1_224_1543_Open_Image.style.display='inline'; Codehighlighter1_224_1543_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>        </span><span id=Codehighlighter1_224_1543_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_224_1543_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br><img id=Codehighlighter1_251_1217_Open_Image onclick="this.style.display='none'; Codehighlighter1_251_1217_Open_Text.style.display='none'; Codehighlighter1_251_1217_Closed_Image.style.display='inline'; Codehighlighter1_251_1217_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_251_1217_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_251_1217_Closed_Text.style.display='none'; Codehighlighter1_251_1217_Open_Image.style.display='inline'; Codehighlighter1_251_1217_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>         </span><span id=Codehighlighter1_251_1217_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_251_1217_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> port </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2010</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> host </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">127.0.0.1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            IPAddress ip </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> IPAddress.Parse(host);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            IPEndPoint ipe </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> IPEndPoint(ip, port);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">把ip和端口{化ؓIPEndPoint实例</span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">            Socket c </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">创徏一个Socket</span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">            Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Conneting<img src="http://www.shnenglu.com/Images/dot.gif"></span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            c.Connect(ipe);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">q接到服务器</span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> sendStr </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">hello!This is a socket test</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] bs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Encoding.ASCII.GetBytes(sendStr);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Send Message</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            c.Send(bs, bs.Length, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">发送测试信?/span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> recvStr </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] recvBytes </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> bytes;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            bytes </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> c.Receive(recvBytes, recvBytes.Length, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">从服务器端接受返回信?/span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">            recvStr </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> Encoding.ASCII.GetString(recvBytes, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, bytes);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Client Get Message:{0}</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, recvStr);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">昄服务器返回信?/span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">                c.Close();<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>         }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>         </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (ArgumentNullException e)<br><img id=Codehighlighter1_1269_1344_Open_Image onclick="this.style.display='none'; Codehighlighter1_1269_1344_Open_Text.style.display='none'; Codehighlighter1_1269_1344_Closed_Image.style.display='inline'; Codehighlighter1_1269_1344_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1269_1344_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1269_1344_Closed_Text.style.display='none'; Codehighlighter1_1269_1344_Open_Image.style.display='inline'; Codehighlighter1_1269_1344_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>         </span><span id=Codehighlighter1_1269_1344_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_1269_1344_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ArgumentNullException: {0}</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, e);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>         }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>         </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (SocketException e)<br><img id=Codehighlighter1_1390_1459_Open_Image onclick="this.style.display='none'; Codehighlighter1_1390_1459_Open_Text.style.display='none'; Codehighlighter1_1390_1459_Closed_Image.style.display='inline'; Codehighlighter1_1390_1459_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1390_1459_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1390_1459_Closed_Text.style.display='none'; Codehighlighter1_1390_1459_Open_Image.style.display='inline'; Codehighlighter1_1390_1459_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>         </span><span id=Codehighlighter1_1390_1459_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_1390_1459_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">SocketException: {0}</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, e);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>         }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>     Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Press Enter to Exit</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        Console.ReadLine();<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>      }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span></div> <p>服务端:<br></p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.Collections.Generic;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.Text;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.IO;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.Net;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System.Net.Sockets;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> ServerDemo<br><img id=Codehighlighter1_150_1751_Open_Image onclick="this.style.display='none'; Codehighlighter1_150_1751_Open_Text.style.display='none'; Codehighlighter1_150_1751_Closed_Image.style.display='inline'; Codehighlighter1_150_1751_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_150_1751_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_150_1751_Closed_Text.style.display='none'; Codehighlighter1_150_1751_Open_Image.style.display='inline'; Codehighlighter1_150_1751_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_150_1751_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_150_1751_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> Program<br><img id=Codehighlighter1_174_1749_Open_Image onclick="this.style.display='none'; Codehighlighter1_174_1749_Open_Text.style.display='none'; Codehighlighter1_174_1749_Closed_Image.style.display='inline'; Codehighlighter1_174_1749_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_174_1749_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_174_1749_Closed_Text.style.display='none'; Codehighlighter1_174_1749_Open_Image.style.display='inline'; Codehighlighter1_174_1749_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_174_1749_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_174_1749_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Main(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">[] args)<br><img id=Codehighlighter1_224_1743_Open_Image onclick="this.style.display='none'; Codehighlighter1_224_1743_Open_Text.style.display='none'; Codehighlighter1_224_1743_Closed_Image.style.display='inline'; Codehighlighter1_224_1743_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_224_1743_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_224_1743_Closed_Text.style.display='none'; Codehighlighter1_224_1743_Open_Image.style.display='inline'; Codehighlighter1_224_1743_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>        </span><span id=Codehighlighter1_224_1743_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_224_1743_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> <br><img id=Codehighlighter1_255_1408_Open_Image onclick="this.style.display='none'; Codehighlighter1_255_1408_Open_Text.style.display='none'; Codehighlighter1_255_1408_Closed_Image.style.display='inline'; Codehighlighter1_255_1408_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_255_1408_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_255_1408_Closed_Text.style.display='none'; Codehighlighter1_255_1408_Open_Image.style.display='inline'; Codehighlighter1_255_1408_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>            </span><span id=Codehighlighter1_255_1408_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_255_1408_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> port </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2010</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> host </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">127.0.0.1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                IPAddress ip </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> IPAddress.Parse(host);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                IPEndPoint ipe </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> IPEndPoint(ip, port);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                Socket s </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 创徏一个SOKCETcȝ实例</span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">                s.Bind(ipe);    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> l定端口</span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">                s.Listen(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 开始监?/span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">                Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Wait for connect</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                Socket temp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> s.Accept();</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 为新接创建新的Socket</span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">                Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Get a Connect</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> recvStr </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] recvBytes </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> bytes;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                bytes </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> temp.Receive(recvBytes, recvBytes.Length, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">  接收客户端的信息</span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">                recvStr </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> Encoding.ASCII.GetString(recvBytes, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, bytes);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Server Get Message:{0}</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, recvStr);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> sendStr </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">OK! Client Send Message Successful!</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] bs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Encoding.ASCII.GetBytes(sendStr);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                temp.Send(bs, bs.Length, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                temp.Close();<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>                s.Close();<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>            }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (ArgumentNullException e)<br><img id=Codehighlighter1_1463_1538_Open_Image onclick="this.style.display='none'; Codehighlighter1_1463_1538_Open_Text.style.display='none'; Codehighlighter1_1463_1538_Closed_Image.style.display='inline'; Codehighlighter1_1463_1538_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1463_1538_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1463_1538_Closed_Text.style.display='none'; Codehighlighter1_1463_1538_Open_Image.style.display='inline'; Codehighlighter1_1463_1538_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>         </span><span id=Codehighlighter1_1463_1538_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_1463_1538_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ArgumentNullException: {0}</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, e);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>         }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>         </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (SocketException e)<br><img id=Codehighlighter1_1584_1653_Open_Image onclick="this.style.display='none'; Codehighlighter1_1584_1653_Open_Text.style.display='none'; Codehighlighter1_1584_1653_Closed_Image.style.display='inline'; Codehighlighter1_1584_1653_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_1584_1653_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1584_1653_Closed_Text.style.display='none'; Codehighlighter1_1584_1653_Open_Image.style.display='inline'; Codehighlighter1_1584_1653_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>         </span><span id=Codehighlighter1_1584_1653_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_1584_1653_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">SocketException: {0}</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, e);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>         }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>         Console.WriteLine(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Press Enter to Exit</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>         Console.ReadLine();<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>        }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span></div> <p><br>面的例子是用的Socketc,System.Net.Socket命名I间q提供了两个抽象高cTCPClient和UDPClient和用于通讯处理的NetWorkStream,让我们看下例?/p> <p>  客户?/p> <p>TcpClient tcpClient=new TcpCLient(LIP,端口?;<br>NetworkStream ns=tcp.Client.GetStream(); </p> <p>  服务?/p> <p>TcpListener tcpListener=new TcpListener(监听端口);<br>tcpListener.Start();<br>TcpClient tcpClient=tcpListener.AcceptTcpClient();<br>NetworkStream ns=tcpClient.GetStream(); </p> <p>  服务端用TcpListener监听,然后把连接的对象实例化ؓ一个TcpClient,调用TcpClient.GetStream()Ҏ,q回|络实例化Z个NetworlStream?下面是用流的方法进行Send,Receive</p> <p>   如果是UdpClient的话,q接UdpClient实例?然后调用UdpClient的Send和ReceiveҎ,需要注意的? UdpClient没有q回|络的Ҏ,是说没有GetStreamҎ,所以无法流?而且使用Udp通信的时?不要服务器监听?/p> <p>  现在我们大致了解?Net Socket通信的流E,下面我们来作一个稍微复杂点的程序,一个广播式的C/S聊天E序?/p> <p>  客户端设计需要一?个ListBoxQ用于显C天内容,一个TextBox输入你要说的话,一个Button发送留aQ一个Button建立q接?/p> <p>  点击建立q接的Button后出来一个对话框Q提C入连接服务器的IPQ端口,和你的昵Uͼ启动一个接受线E,负责接受从服务器传来的信息ƈ昄在ListBox上面?/p> <p>  服务器端2个ButtonQ一个启动服务,一个T掉已建立q接的客LQ一个ListBox昄q接上的客户端的Ip和端口?/p> <p>  比较重要的地Ҏ字符串编码的问题Q需要先把需要传送的字符串按照UTF8~码Q然后接受的时候再q原成ؓGB2312Q不然中文显CZ是ؕ码?/p> <p>  q有一个就是接收线E,我这里简单写成一个While(ture)循环Q不断判断是否有信息入Q有接Ӟq显C在ListBox上,q里有问题,?Net2.0里面Q交错线E修改窗体空间属性的时候会引发一个异常,不可以直接修改,需要定义一个委托来修改?</p> <p>   当客L需要断开q接的时候,比如点击H体右上角的XXQ就需要定义一个this.FormClosing +=  new System.Windows.Forms.FormClosingEventHandler(this.Closing);Q?Net2.0 是FormClosingpȝ事gQ,在Closing()函数里面Q发送Close字符l服务端Q服务器判断循环判断所有的q接上的客户端传来的信息Q?如果是以Close开_断开与其的连接。看到这里,读者就会问了,如果我在聊天H口输入Close是不是也断开q接呢?不是的,在聊天窗口输入的信息?l服务器的时候开头都要加上Ip信息和昵Uͼ所以不会冲H?nbsp; </p> <p><br>本文来自CSDN博客Q{载请标明出处Q?a >http://blog.csdn.net/dzfb/archive/2006/12/21/1452139.aspx</a><a ></a></p> <img src ="http://www.shnenglu.com/Lee7/aggbug/102299.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Lee7/" target="_blank">isabc</a> 2009-11-30 19:17 <a href="http://www.shnenglu.com/Lee7/archive/2009/11/30/102299.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c#中Setting.setting的?/title><link>http://www.shnenglu.com/Lee7/archive/2009/11/26/102000.html</link><dc:creator>isabc</dc:creator><author>isabc</author><pubDate>Thu, 26 Nov 2009 12:00:00 GMT</pubDate><guid>http://www.shnenglu.com/Lee7/archive/2009/11/26/102000.html</guid><wfw:comment>http://www.shnenglu.com/Lee7/comments/102000.html</wfw:comment><comments>http://www.shnenglu.com/Lee7/archive/2009/11/26/102000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Lee7/comments/commentRss/102000.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Lee7/services/trackbacks/102000.html</trackback:ping><description><![CDATA[<p><span style="FONT-SIZE: medium"><span style="COLOR: #3366ff"><font size=3>1、定?/font></span></span></p> <p><span style="FONT-SIZE: medium"><font size=3>在Settings.settings文g中定义配|字Dc把作用范围定义为:User则运行时可更改,Applicatiion则运行时不可更改。可以用数据网D图,很方便;</font></span></p> <p><span style="FONT-SIZE: medium"><span style="COLOR: #3366ff"><font size=3>2、读取配|?/font></span></span></p> <p><span style="FONT-SIZE: medium"><font size=3>text1.text = Properties.Settings.Default.FieldName;<br>//FieldName是你定义的字D?/font></span></p> <p><span style="FONT-SIZE: medium"><span style="COLOR: #3366ff"><font size=3>3、修改和保存配置</font></span></span></p> <p><span style="FONT-SIZE: medium"><font size=3>Properties.Settings.Default.FieldName = "server";<br></font></span></p> <p><span style="FONT-SIZE: medium"><font size=3>Properties.Settings.Default.Save();//使用SaveҎ保存更改</font></span></p> <p><span style="FONT-SIZE: medium"><font size=3>注意Q当讄scope为User时他的配|放?C:\Documents and Settings\LocalService\Local Settings\Application Data\在这个目录下或子目录user.config 配置文g中?/font><br></span></p> <img src ="http://www.shnenglu.com/Lee7/aggbug/102000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Lee7/" target="_blank">isabc</a> 2009-11-26 20:00 <a href="http://www.shnenglu.com/Lee7/archive/2009/11/26/102000.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C# 装箱和拆[转] http://www.shnenglu.com/Lee7/archive/2009/09/27/97361.htmlisabcisabcSun, 27 Sep 2009 06:45:00 GMThttp://www.shnenglu.com/Lee7/archive/2009/09/27/97361.htmlhttp://www.shnenglu.com/Lee7/comments/97361.htmlhttp://www.shnenglu.com/Lee7/archive/2009/09/27/97361.html#Feedback0http://www.shnenglu.com/Lee7/comments/commentRss/97361.htmlhttp://www.shnenglu.com/Lee7/services/trackbacks/97361.html      装箱和拆是一个抽象的概念
2?br>      装箱是将值类?/span>转换?span style="COLOR: #0000ff">引用cd Q拆是?span style="COLOR: #0000ff">引用cd转换?span style="COLOR: #0000ff">值类?/span> 
      利用装箱和拆功能,可通过允许值类?/span>的Q何gObject cd的值相互{换,值类型与引用cd链接h
例如Q?
int val = 100;
object obj = val;
Console.WriteLine (“对象的?= {0}", obj);
q是一个装qq程Q是?span style="COLOR: red">值类?/span>转换?span style="COLOR: red">引用cd
的过E?

int val = 100;
object obj = val;
int num = (int) obj;
Console.WriteLine ("num: {0}", num);
q是一个拆qq程Q是值类型{换ؓ引用cdQ再由引用类型{换ؓ值类型的q程

注:被装q箱的对象才能被拆箱
3?br>      .NET中,数据cd划分?span style="COLOR: #0000ff">值类?/span>?span style="COLOR: #0000ff">引用(不等同于C++的指?cdQ与此对应,内存分配被分成了两种方式Q一为栈Q二为堆Q注意:是托堆?br>      值类型只会在栈中分配?br>      引用cd分配内存与托堆?br>      托管堆对应于垃圾回收?br>

4Q装?拆箱是什么?
装箱Q用于在垃圾回收堆中存储值类型。装是值类型到 object cd或到此值类型所实现的Q何接口类型的隐式转换?
拆箱Q从 object cd到值类型或从接口类型到实现该接口的值类型的昑ּ转换?

5Qؓ何需要装?(Z要将值类型{为引用类型?)
一U最普通的场景是,调用一个含cd为Object的参数的ҎQ该Object可支持Q意ؓ型,以便通用。当你需要将一个值类?如Int32)传入Ӟ需要装?
另一U用法是Q一个非泛型的容器,同样是ؓ了保证通用Q而将元素cd定义为Object。于是,要将值类型数据加入容器时Q需要装?

6Q装?拆箱的内部操作?
装箱Q?
对值类型在堆中分配一个对象实例,q将该值复制到新的对象中。按三步q行?
W一步:新分配托堆内存(大小为值类型实例大加上一个方法表指针和一个SyncBlockIndex)?
W二步:值类型的实例字段拯到新分配的内存中?
W三步:q回托管堆中新分配对象的地址。这个地址是一个指向对象的引用了?
有hq样理解Q如果将Int32装箱Q返回的地址Q指向的是一个Int32。我认ؓ也不是不能这L解,但这实又有问题Q一来它不全面,二来指向Int32q没说出它的实质(在托堆??
拆箱Q?br>查对象实例,保它是l定值类型的一个装倹{将该g实例复制到值类型变量中?
有书上讲Q拆只是获取引用对象中指向值类型部分的指针Q而内Ҏ贝则是赋D句之触发。我觉得qƈ不要紧。最关键的是查对象实例的本质Q拆和装箱的类型必需匚wQ这一点上Q在IL层上Q看不出原理何在Q我的猜,或许是调用了cMGetType之类的方法来取出cdq行匚w(因ؓ需要严格匹??

7Q装?拆箱Ҏ行效率的影响
昄Q从原理上可以看出,装箱Ӟ生成的是全新的引用对象,q会有时间损耗,也就是造成效率降低?
那该如何做呢Q?
首先Q应该尽量避免装?
比如上例2的两U情况,都可以避免,在第一U情况下Q可以通过重蝲函数来避免。第二种情况Q则可以通过泛型来避免?
当然Q凡事ƈ不能l对Q假设你x造的代码为第三方E序集,你无法更改,那你只能是装׃?
对于装箱/拆箱代码的优化,׃C#中对装箱和拆都是隐式的Q所以,Ҏ的方法是对代码进行分析,而分析最直接的方式是了解原理l何查看反编译的IL代码。比如:在@环体中可能存在多余的装箱Q你可以单采用提前装方式进行优化?

8Q对装箱/拆箱更进一步的了解
装箱/拆箱q不如上面所讲那么简单明了,比如Q装时Q变为引用对象,会多Z个方法表指针Q这会有何用处呢Q?
我们可以通过CZ来进一步探讨?
举个例子?
Struct A : ICloneable
{
public Int32 x;
public override String ToString() {
return String.Format(”{0}”,x);
}
public object Clone() {
return MemberwiseClone();
}
}
static void main()
{
A a;
a.x = 100;
Console.WriteLine(a.ToString());
Console.WriteLine(a.GetType());
A a2 = (A)a.Clone();
ICloneable c = a2;
Ojbect o = c.Clone();
}
5.0Qa.ToString()。编译器发现A重写了ToStringҎQ会直接调用ToString的指令。因为A是值类型,~译器不会出现多态行为。因此,直接调用Q不装箱?注:ToString是A的基cSystem.ValueType的方?
5.1Qa.GetType()QGetType是承于System.ValueType的方法,要调用它Q需要一个方法表指针Q于是a被装箱Q从而生成方法表指针Q调用基cȝSystem.ValueType?补一句,所有的值类型都是承于System.ValueType??
5.2Qa.Clone()Q因为A实现了CloneҎQ所以无需装箱?
5.3QICloneable转型Q当a2{为接口类型时Q必装,因ؓ接口是一U引用类型?
5.4Qc.Clone()。无需装箱Q在托管堆中对上一步已装箱的对象进行调用?
附:其实上面的基于一个根本的原理Q因为未装箱的值类型没有方法表指针Q所以,不能通过值类型来调用其上l承的虚Ҏ。另外,接口cd是一个引用类型。对此,我的理解Q该Ҏ表指针类似C++的虚函数表指针,它是用来实现引用对象的多态机制的重要依据?

9Q如何更改已装箱的对?
对于已装q对象Q因为无法直接调用其指定ҎQ所以必d拆箱Q再调用ҎQ但再次拆箱Q会生成新的栈实例,而无法修改装对象。有Ҏ吧,感觉在说l口令。还是D个例子来_(在上例中q加changeҎ)
public void Change(Int32 x) {
this.x = x;
}
调用Q?
A a = new A();
a.x = 100;
Object o = a; //装箱成oQ下面,x变o的倹{?
((A)o).Change(200); //Ҏ了吗Q没Ҏ?
没改掉的原因是o在拆时Q生成的是时的栈实例AQ所以,改动是基于时A的,q未改到装箱对象?
(附:在托C++中,允许直接取加拆箱时第一步得到的实例引用Q而直接更改,但C#不行?
那该如何是好Q?
嗯,通过接口方式Q可以达到相同的效果?
实现如下Q?
interface IChange {
void Change(Int32 x);
}
struct A : IChange {

}
调用Q?
((IChange)o).Change(200);//Ҏ了吗Q改掉了?
为啥现在可以改?
在将o转型为IChangeӞq里不会q行再次装箱Q当然更不会拆箱Q因为o已经是引用类型,再因为它是IChangecdQ所以可以直接调用ChangeQ于是,更改的也是已装对象中的字D了Q达到期望的效果?br>
10?/strong>--------------------------
      值类型{换ؓ引用cdQ需要进行装操?boxing)Q?/p>

1、首先从托管堆中为新生成的引用对象分配内存?/p>

2、然后将值类型的数据拯到刚刚分配的内存中?/p>

3、返回托堆中新分配对象的地址?/p>

可以看出Q进行一ơ装pq行分配内存和拷贝数据这两项比较影响性能的操作?/p>

引用内型{换ؓ值内型,需要进行拆操?unboxing)Q?/p>

1、首先获取托堆中属于值类型那部分字段的地址Q这一步是严格意义上的拆箱?/p>

2、将引用对象中的值拷贝到位于U程堆栈上的值类型实例中?/p>

l过q?步,可以认ؓ是同boxing是互反操作。严格意义上的拆,q不影响性能Q但伴随q之后的拯数据的操作就会同boxing操作中一样媄响性能?br>
11?/strong>-------------------------
NET的所有类型都是由基类System.Objectl承q来的,包括最常用的基cdQint, byte, shortQbool{等Q就是说所有的事物都是对象。如果申明这些类型得时候都在堆(HEAP)中分配内存,会造成极低的效率!(个中原因以及关于堆和栈得区别会在另一里单独得说_)
.NET如何解决q个问题得了Q正是通过类型分成值型(value)和引用型(regerencetype)QC#中定义的值类型包括原cdQ?span style="COLOR: green">Sbyte、Byte、Short、Ushort、Int、Uint、Long、Ulong、Char、Float、Double、Bool、DecimalQ、枚?enum)、结?struct)Q引用类型包括:cR数l、接口、委托、字W串{?br>值型是在栈中分配内存,在申明的同时初始化Q以保数据不ؓNULLQ?br>引用型是在堆中分配内存,初始化ؓnullQ引用型是需要GARBAGE COLLECTION来回收内存的Q值型不用Q超Z作用范围Q系l就会自动释放!
下面来说装和拆箱的定义!
装箱是隐式的将一个值型转换为引用型对象。比如:
int i=0;
Syste.Object obj=i;

q个q程是装箱Q就是将i装箱Q?br>拆箱是一个引用型对象转换成Q意值型Q比如:
int i=0;
System.Object obj=i;
int j=(int)obj;

q个q程?句是i装箱Q后一句是obj拆箱Q?/p>

isabc 2009-09-27 14:45 发表评论
]]>
安装VS2008注意拉!http://www.shnenglu.com/Lee7/archive/2009/09/03/95220.htmlisabcisabcThu, 03 Sep 2009 08:16:00 GMThttp://www.shnenglu.com/Lee7/archive/2009/09/03/95220.htmlhttp://www.shnenglu.com/Lee7/comments/95220.htmlhttp://www.shnenglu.com/Lee7/archive/2009/09/03/95220.html#Feedback0http://www.shnenglu.com/Lee7/comments/commentRss/95220.htmlhttp://www.shnenglu.com/Lee7/services/trackbacks/95220.html׃一天多旉l于安装好了VS2008Q而且是在 xp 和Vista2U系l下都安装了,其实开始是p|?找了好多资料才找到原?VS2008安装之前需要在"服务"中启动以?Ҏ?
Distributed Transaction Coordinator

WMI Performance Adapter

默认?Ҏ务是止?



isabc 2009-09-03 16:16 发表评论
]]>
VC6.0实现鼠标昄按钮功能提示文本http://www.shnenglu.com/Lee7/archive/2009/07/16/90229.htmlisabcisabcThu, 16 Jul 2009 07:04:00 GMThttp://www.shnenglu.com/Lee7/archive/2009/07/16/90229.htmlhttp://www.shnenglu.com/Lee7/comments/90229.htmlhttp://www.shnenglu.com/Lee7/archive/2009/07/16/90229.html#Feedback7http://www.shnenglu.com/Lee7/comments/commentRss/90229.htmlhttp://www.shnenglu.com/Lee7/services/trackbacks/90229.html

本文?/span>VC6.0对话框应用程序ؓ例,当鼠标在按钮上移动、按下或者弹h昄按钮功能提示文本Q本文将在按钮上昄功能提示文本Q?font face="Times New Roman">“IT知道|?/font>?/font>
?font face="Times New Roman">CXXXDlg.h
文g中定义:

public:
  CToolTipCtrl m_openToolTip; 
 
?font face="Times New Roman">CXXXDlg.cpp
?/font>OnInitDialog()中初始化Q?nbsp;
 m_openToolTip.Create(this); 
 m_openToolTip.AddTool( GetDlgItem(IDC_BOTTON), "IT知道|?/font>" );
 m_openToolTip.SetDelayTime(200);
 m_openToolTip.SetTipTextColor( #0000ff );
 m_openToolTip.SetTipBkColor( #ffffff);
 m_openToolTip.Activate(TRUE);
 
重蝲函数PreTranslateMessage
BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg)
{
 // TODO: Add your specialized code here and/or call the base class
 switch(pMsg->message)
 {
 case WM_LBUTTONDOWN:
 case WM_LBUTTONUP:
 case WM_MOUSEMOVE:
  m_openToolTip.RelayEvent(pMsg);
 }

 return CDialog::PreTranslateMessage(pMsg);



isabc 2009-07-16 15:04 发表评论
]]>
[转]如何安装EVC以及如何配置EVC(含EVC序列?http://www.shnenglu.com/Lee7/archive/2009/07/14/90023.htmlisabcisabcTue, 14 Jul 2009 06:20:00 GMThttp://www.shnenglu.com/Lee7/archive/2009/07/14/90023.htmlhttp://www.shnenglu.com/Lee7/comments/90023.htmlhttp://www.shnenglu.com/Lee7/archive/2009/07/14/90023.html#Feedback0http://www.shnenglu.com/Lee7/comments/commentRss/90023.htmlhttp://www.shnenglu.com/Lee7/services/trackbacks/90023.html因ؓ最q在学习嵌入式在WinCEq_的开?/font>

所以需要在机器上安装了EVC4.0和SP4Q结果运行程序出玎ͼ
"One or more files from the Emulator for Windows CE installation is missing. Please reinstall Emulator for Windows CE and try again."

解决办法Q按照上面的Ҏq入讑֤理器-Q高U-Q启动和故障恢复(选择讄)->在启动和故障恢复对话框中选择~辑-> boot.ini 中noexcute修改为execute 然后重启机器可以了?到此我们已经完成开发环境的搭徏?/font>

微Y的安装步骤安?
ActiveSync->eVC4->eVC4 sp4->smartphone SDK->.net framework->模拟器imagesQ在q行安装前,您先查看注意事项?/font>

开发工具下载地址

1QeVC4.0,下蝲地址Q?br>http://download.microsoft.com/download/c/3/f/c3f8b58b-9753-4c2e-8b96-2dfe3476a2f7/eVC4.exe
http://download.microsoft.com/download/a/7/3/a735c7fb-dcbd-429f-9090-d09b3b15d3fa/evc4sp4.exe
eVC序列PTRT7H-KD36T-FRH8D-6QH8P-VFJHQ

2Qsmartphone SDKQpacket PC SDK下蝲地址Q?/font>

smartphone 2003 SDK:
http://www.microsoft.com/downloads/details.aspx?FamilyId=A6C4F799-EC5C-427C-807C-4C0F96765A81&displaylang=en

packet PC 2003 SDK:
http://microsoft.com/downloads/details.aspx?FamilyId=9996B314-0364-4623-9EDE-0B5FBB133652&displaylang=en

3,中文image文g下蝲Q?br>smart phoneQ?br>http://www.microsoft.com/downloads/info.aspx?na=46&p=1&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=2c144e09-7e75-4275-a6bb-1c3cd55369c5&genscs=0&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f6%2fb%2f8%2f6b8d7515-0d0a-4d03-b11c-b31886fbb9ff%2fWindows+Mobile+2003+Second+Edition+Emulator+Images+for+Smartphone+-+CHS.msi

packet PC
http://download.microsoft.com/download/e/2/8/e28792ca-d04b-407b-9b18-75b9128f0cc9/Windows%20Mobile%202003%20Second%20Edition%20Emulator%20Images%20for%20Pocket%20PC%20-%20CHS.msi

4Q安装image文gQ安装完后你q没有发C的模拟器变成中文的,q时需要如下操作:

C:\Program Files\Pocket PC 2003 Emulation\CHS\Pocket_PC\PPC_2003_CHS.bin

把这个文件改个名UCؓPPC_2003_WWE.bin,然后替换下面q个目录下的文g此文?br>C:\Program Files\Windows CE Tools\wce420\POCKET PC 2003\Emulation\PPC_2003_WWE.bin

EVC中设|:
a,打开eVCQ选择tools-->Platform Manager Configuration
b,点Add Device,起一个名字,然后点properties.在Transpor中选择"TCP/IP ....",StartUp用默认的"Emulator Startup Server"
c,点StartUp双的Configuration,在image中选择"CHS SP 2003 SE(Virtual Radio)",然后一路OK点回厅R就可以在eVC的编译工h选择中文模拟器了。而且可以中英随意切换

5,注意事项Q?/strong>
要保证你的VBS脚本服务器能正常q行Q网上很多h装不 成功Q都是因为VBS脚本没有正常执行。如果你装了解霸Q一定要注意Q因U解怼更改 VBS文g的打开方式Q最好是把解霸先卸蝲Q卸载后再进?#8220;文g多w项”?#8220;文gcd”中恢复VBS的默认打开方式。手动更Ҏ开方式好像不行?br>如果你安装完后,发现q个错误QCVTRES : fatal error CVT1102: out of memory。请用安装目录下面的\Common\EVC\Bin\CVTRES.EXE覆盖EVC\wce420\bin\下面的同名文件试?/font>

其中Chinese (Simplified) Emulation ImagesQ是Pocket PC 2003 SDK的中文印象文Ӟ不能昄中文的问题把英文模拟器对应的快捷方式攑ֈ中文模拟器的目录下,改一下里面的SKIN和BIN文g路径Q运行一下,再把 EVC打开Q在configure platform manager中设|一下连C文模拟器上就可以了?/font>


转自:http://www.2guys.cn/collection/17461620481620.html



isabc 2009-07-14 14:20 发表评论
]]>
[转]Windows Mobile(Win CE)开发工具下?/title><link>http://www.shnenglu.com/Lee7/archive/2009/07/14/90018.html</link><dc:creator>isabc</dc:creator><author>isabc</author><pubDate>Tue, 14 Jul 2009 06:13:00 GMT</pubDate><guid>http://www.shnenglu.com/Lee7/archive/2009/07/14/90018.html</guid><wfw:comment>http://www.shnenglu.com/Lee7/comments/90018.html</wfw:comment><comments>http://www.shnenglu.com/Lee7/archive/2009/07/14/90018.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Lee7/comments/commentRss/90018.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Lee7/services/trackbacks/90018.html</trackback:ping><description><![CDATA[<strong><font color="#ffffff">Windows Mobile(</font></strong> <p><font size="3">l常有朋友想学习 Windows Mobile 开发,体验Ud开发的乐趣Q但不知道从哪里下蝲各种开发工具和学习资料。于是我整理了一个列表,里面包含了各个版本的 Windows Mobile SDK, .NET Compact Framework, SQL Server CE, Device Emulator, Emulator Image 和学习资料的下蝲链接?br><br>如果你发现还有其他不错的工具没有在这个列表中Q请告诉我,我会把它加入到这个列表中Q让更多的h用上?br></font></p> <h2><font size="3">1) Software Development Kit</font></h2> <p><a title="This version of the pocket pc 2003 sdk allows you to create pocket pc 2003 applications using embedded visual c++ 4.0 (with service pack 3), and applications written in c# or visual basic .net using visual studio .net 2003." target="_blank"><font color="#56b6e9" size="3">Windows Mobile 2003 SDK for Pocket PC</font></a><font size="3"> (</font><a target="_blank"><font color="#56b6e9" size="3">直接下蝲</font></a><font size="3">)<br></font><a title="Build applications for windows mobile 2003-based smartphones leveraging the microsoft® .net compact framework, windows ce. net 4.2, an improved emulator and new atl support." target="_blank"><font color="#56b6e9" size="3">Windows Mobile 2003 SDK for Smartphone</font></a><br><a title="The windows mobile 5.0 sdk for pocket pc extends visual studio 2005 so that you can write managed and native application software targeting windows mobile 5.0 based pocket pc devices." target="_blank"><font color="#56b6e9" size="3">Windows Mobile 5.0 SDK for Pocket PC</font></a><font size="3"> (</font><a target="_blank"><font color="#56b6e9" size="3">直接下蝲</font></a><font size="3">)<br></font><a title="The windows mobile 5.0 sdk for smartphone extends visual studio 2005 so that you can write managed and native application software targeting windows mobile 5.0 based smartphone devices." target="_blank"><font color="#56b6e9" size="3">Windows Mobile 5.0 SDK for Smartphone</font></a><br><a title="The windows mobile 6 sdks add documentation, sample code, header and library files, emulator images and tools to visual studio that let you build applications for windows mobile 6." target="_blank"><font color="#56b6e9" size="3">Windows Mobile 6 SDK</font></a><br><a title="The Windows CE 5.0: Standard SDK, in conjunction with the Microsoft eMbedded Visual C++ 4.0 SP4, deliver a complete development environment for creating applications for devices based on Microsoft® Windows® CE 5.0."><font color="#56b6e9" size="3">Windows CE 5.0: Standard Software Development Kit (SDK)<br></font></a><br></p> <h2><font size="3">2) .NET Compact Framework</font></h2> <p><a title="The microsoft® .net compact framework 1.0 sp3 redistributable includes everything you need to run .net compact framework applications, including the common language runtime and the .net compact framework class library." target="_blank"><font color="#56b6e9" size="3">.NET Compact Framework 1.0 SP3 Redistributable</font></a><br><a title="The microsoft® .net compact framework 2.0 service pack 1 redistributable includes everything you need to run .net compact framework 1.0 and 2.0 applications." target="_blank"><font color="#56b6e9" size="3">.NET Compact Framework 2.0 Service Pack 1 Redistributable</font></a><br><a title="The microsoft® .net compact framework 2.0 service pack 1 patch includes everything you need to update the .net compact framework 2.0 to the .net compact framework 2.0 sp1." target="_blank"><font color="#56b6e9" size="3">.NET Compact Framework 2.0 Service Pack 1 Patch</font></a><a title="The microsoft® .net compact framework 2.0 service pack 2 redistributable includes everything you need to run .net compact framework 1.0 and 2.0 applications." target="_blank"><br><font color="#56b6e9" size="3">.NET Compact Framework 2.0 Service Pack 2 Redistributable</font></a><br><a target="_blank"><font color="#56b6e9" size="3">.NET Compact Framework 3.5 Redistributable<br></font></a><a ><font color="#56b6e9" size="3">Power Toys for .NET Compact Framework 3.5</font></a><br></p> <h2><font size="3">3) SQL Server CE</font></h2> <p><a title="SQL server 2000 windows ce edition (sql server ce) version 2.0 is the compact database for rapidly developing applications in both native mode and the .net compact framework that extend enterprise data management capabilities to devices. companies and users of sql server ce that have upgraded sql server 2000 database and publisher servers to the service pack 4 (sp4) release should also update the server replication components on servers running internet information services (iis). this release of sql server ce server tools updates the servers running iis to support connectivity solutions to sql server 2000 sp4 databases." target="_blank"><font color="#56b6e9" size="3">SQL Server CE 2.0 Server Tools SP4</font></a><a title="Microsoft sql server 2005 compact edition (sql server compact edition) is designed for developers who need light weight, in process relational database solution for their applications that can be developed and deployed on desktop as well as on mobile devices." target="_blank"><br><font color="#56b6e9" size="3">SQL Server 2005 Compact Edition</font></a><br><a title="Microsoft sql server 2005 compact edition tools for visual studio 2005 software updates the microsoft visual studio 2005 sp1 smart device development components with the design time environment for microsoft sql server 2005 compact edition." target="_blank"><font color="#56b6e9" size="3">SQL Server 2005 Compact Edition Tools for Visual Studio 2005 Service Pack 1</font></a><br><a title="Microsoft sql server 2005 compact edition server tools updates the servers running iis to support connectivity solutions from sql server 2005 compact edition database on a mobile device or a desktop or a tablet pc to database servers running sql server 2000 sp3a and above versions." target="_blank"><font color="#56b6e9" size="3">SQL Server 2005 Compact Edition Server Tools<br></font></a><a title="SQL server compact edition (ssce) books online and readme." target="_blank"><font color="#56b6e9" size="3">SQL Server 2005 Compact Edition Books Online (March 2007)<br></font></a><a title="Microsoft sql server 2005 compact edition access database synchronizer provides a way to synchronize data between microsoft access database on a desktop and microsoft sql server 2005 compact edition database on a device." target="_blank"><font color="#56b6e9" size="3">SQL Server 2005 Compact Edition Access Database Synchronizer</font></a><br><a class="" mce_><font color="#56b6e9" size="3">SQL Server Compact 3.5 for Windows Desktop</font></a><br><a class="" mce_><font color="#56b6e9" size="3">SQL Server Compact 3.5 Books Online and Samples</font></a><br><a class="" mce_><font color="#56b6e9" size="3">Synchronization Services for ADO.NET Books Online<br></font></a><a target="_blank"><font color="#56b6e9" size="3">ADOCE 3.1 for Windows 3.0 SDKs</font></a></p> <h2><font size="3">4) Device Emulator</font></h2> <p><a title="The microsoft device emulator 1.0 is a standalone version of the same arm based device emulator that ships as part of visual studio 2005. the standalone emulator is intended for situations when you want to demonstrate or test your application on a computer that does not have visual studio 2005 installed. in addition, we are offering the windows mobile 5.0 msfp operating system images that you can use with the device emulator." target="_blank"><font color="#56b6e9" size="3">Standalone Device Emulator 1.0 with Windows Mobile OS Images</font></a><br><a title="Microsoft device emulator 2.0 is the second publicly released version of the device emulator for arm-based devices. this emulator is also being released with the windows mobile 6 sdk and the adaptation kit (ak) releases of windows mobile 6 and windows embedded ce 6.0." target="_blank"><font color="#56b6e9" size="3">Microsoft Device Emulator 2.0 Standalone</font></a><br><a title="The virtual machine network driver allows the device emulator's os (or even the virtual pc os, as the case may be) to emulate its own network connection. because the physical network interface on the host machine is now "virtualized," you have a way to get two ip addresses - one for the host pc, and one for the operating system that is running within the device emulator (or virtual pc). device emulator users using the vmnet driver can connect to the host machine over tcp or udp as the alternative to the standard "activesync over dma" solution." target="_blank"><font color="#56b6e9" size="3">Virtual Machine Network Driver for Microsoft Device Emulator</font></a><br><a title="The device emulator contains the emulator technologies featured in windows ce 5.0. by using the device emulator, you can run emulated-based images created by windows ce 5.0 without installing platform. builder, its platform. development tool." target="_blank"><font color="#56b6e9" size="3">Microsoft Windows CE 5.0 Device Emulator</font></a><br><br></p> <h2><font size="3">5) Emulator Image</font></h2> <p><a title="Emulator images that allow you to test your applications in all available pocket pc 2003 languages." target="_blank"><font color="#56b6e9" size="3">Emulator Images for Windows Mobile 2003-based Pocket PC Development</font></a><font size="3"> <br></font><a title="Emulator images that allow you to test your applications in all available smartphone 2003 localizations." target="_blank"><font color="#56b6e9" size="3">Emulator Images for Windows Mobile 2003-based Smartphone Development</font></a><br><a title="Download new Emulator Images that allow you to test your applications in all available Pocket PC 2003 Second Edition languages."><font color="#56b6e9" size="3">Emulator Images for Windows Mobile 2003 Second Edition-based Pocket PC Development</font></a><br><a title="Download new Emulator Images that allow you to test your applications in all available Smartphone 2003 Second Edition localizations."><font color="#56b6e9" size="3">Emulator Images for Windows Mobile 2003 Second Edition-based Smartphone Development</font></a><br><a title="Emulator images that allow you to test your applications in all available wm5.0 pocket pc localizations." target="_blank"><font color="#56b6e9" size="3">Localized Windows Mobile 5.0 Pocket PC Emulator Images</font></a><br><a title="Emulator images that allow you to test your applications in all available wm5.0 smartphone localizations." target="_blank"><font color="#56b6e9" size="3">Localized Windows Mobile 5.0 Smartphone Emulator Images</font></a></p> <h2><font size="3">6) eMbedded Visual C++</font></h2> <p><a title="The microsoft® embedded visual c++ 4.0 tool delivers a complete desktop development environment for creating applications and system components for windows® ce .net-powered devices." target="_blank"><font color="#56b6e9" size="3">eMbedded Visual C++ 4.0</font></a><br><a title="Service pack 4 (sp4) allows embedded visual c++ 4.0 users to target windows ce 5.0 based devices." target="_blank"><font color="#56b6e9" size="3">eMbedded Visual C++ 4.0 SP4</font></a><br></p> <h2><font size="3">7) OpenNETCF</font></h2> <p><a target="_blank"><font color="#56b6e9" size="3">OpenNETCF Smart Device Framework v1.4</font></a><br><a target="_blank"><font color="#56b6e9" size="3">OpenNETCF Smart Device Framework v2.0</font></a><br></p> <h2><font size="3">8) Mobile Client Software Factory</font></h2> <p><a title="The mobile client software factory provides an integrated set of guidance that assists architects and developers in creating mobile line of business solutions." target="_blank"><font color="#56b6e9" size="3">Mobile Client Software Factory – July 2006<br></font></a><a target="_blank"><font color="#56b6e9" size="3">Architecture Overview for Mobile Applications</font></a><br><a target="_blank"><font color="#56b6e9" size="3">UI Design Considerations in Mobile Applications</font></a><br><a target="_blank"><font color="#56b6e9" size="3">Designing Mobile Applications in an Occasionally-Connected World</font></a><font size="3"> </font></p> <h2><font size="3">9) Other Tools</font></h2> <p><a target="_blank"><font color="#56b6e9" size="3">Microsoft Windows Mobile Device Center 6.1 for Windows Vista (32-bit)<br></font></a><a target="_blank"><font color="#56b6e9" size="3">Microsoft Windows Mobile Device Center 6.1 for Windows Vista (64-bit)<br></font></a><a title="Microsoft activesync 4.5 is the latest sync software release for windows mobile-powered devices. activesync provides a great synchronization experience with windows®-powered pcs and microsoft outlook right out of the box." target="_blank"><font color="#56b6e9" size="3">Microsoft ActiveSync 4.5</font></a><br><a target="_blank"><font color="#56b6e9" size="3">Redistributable Server Components for Windows Mobile 5.0</font></a><br><a title="Device security manager helps developers test various security policies for windows mobile devices." target="_blank"><font color="#56b6e9" size="3">Device Security Manager PowerToy for Windows Mobile 5.0</font></a><br><a title="Network analyzer for windows mobile runs network utilities (e.g., ping and ipconfig) on a windows mobile powered device. network analyzer for windows mobile facilitates the troubleshooting of network connectivity issues." target="_blank"><font color="#56b6e9" size="3">Windows Mobile Network Analyzer PowerToy</font></a><br><a title="The microsoft smart devices remote tools framework is a powertoy for mobile and embedded system developers. the contents of this package demonstrate a new way of building mobile and embedded remote diagnostics/debugging tools in a unified shell." target="_blank"><font color="#56b6e9" size="3">Microsoft Smart Devices Remote Tools Framework Powertoy 1.0</font></a><br><a title="The windows mobile developer power toys help you develop and test your windows mobile applications." target="_blank"><font color="#56b6e9" size="3">Windows Mobile Developer Power Toys</font></a><br> </p> <h2><font size="3">10) Resources</font></h2> <a title="Everything you need to start developing for windows mobile 2003 and windows mobile 5.0-based devices." target="_blank"><font color="#56b6e9" size="3">Windows Mobile 5.0 Developer Resource Kit</font></a><br><a title="MEDC is the leading event for developers, engineers, and business managers. here are presentations from the event about the latest windows embedded and windows mobile® platforms." target="_blank"><font color="#56b6e9" size="3">Microsoft Mobile & Embedded DevCon 2006 DVD</font></a><br><a title="Windows mobility webcasts offers you a full range of pre-recorded instructor-led webcasts covering window mobile development topics and technologies like windows mobile 5.0 pocket pc/smartphone , microsoft visual studio 2005, the .net compact framework 2.0 and sql server mobile. you will be able to view these videos on your own time and without requiring a high-bandwidth data connection for streaming live-webcasts." target="_blank"><font color="#56b6e9" size="3">Windows Mobility Marvels</font></a><br><a title="This resource helps c# developers understand the components involved in creating windows mobile solutions by providing a sample line of business application along with commented source code for a c# visual studio 2005 windows mobile 5.0 project." target="_blank"><font color="#56b6e9" size="3">'Mobile Line of Business Solution Accelerator' kit</font></a><br><br>转自Qhttp://www.2guys.cn/collection/17461619481619.html<strong><font color="#ffffff">Win CE)开发工具下?/font></strong><img src ="http://www.shnenglu.com/Lee7/aggbug/90018.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Lee7/" target="_blank">isabc</a> 2009-07-14 14:13 <a href="http://www.shnenglu.com/Lee7/archive/2009/07/14/90018.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>XML文g格式语法及DTD http://www.shnenglu.com/Lee7/archive/2009/06/28/88691.htmlisabcisabcSun, 28 Jun 2009 06:02:00 GMThttp://www.shnenglu.com/Lee7/archive/2009/06/28/88691.htmlhttp://www.shnenglu.com/Lee7/comments/88691.htmlhttp://www.shnenglu.com/Lee7/archive/2009/06/28/88691.html#Feedback0http://www.shnenglu.com/Lee7/comments/commentRss/88691.htmlhttp://www.shnenglu.com/Lee7/services/trackbacks/88691.html阅读全文

isabc 2009-06-28 14:02 发表评论
]]>
模态对话框和非模态对话框的区?http://www.shnenglu.com/Lee7/archive/2009/06/23/88356.htmlisabcisabcTue, 23 Jun 2009 05:49:00 GMThttp://www.shnenglu.com/Lee7/archive/2009/06/23/88356.htmlhttp://www.shnenglu.com/Lee7/comments/88356.htmlhttp://www.shnenglu.com/Lee7/archive/2009/06/23/88356.html#Feedback0http://www.shnenglu.com/Lee7/comments/commentRss/88356.htmlhttp://www.shnenglu.com/Lee7/services/trackbacks/88356.html模态对话框是指那U?#8220;昄出来׃可以炚w位于其下面的对话框”的对话框Q反之的是非模态对话框?br>两者的区别Q?br>一. 非模态对话框的模板必d有Visible风格(Visible=True)Q否则对话框不可见Q而模态对话框则无需讄该项风格。在实际~程中更加保险的办法是调用CWnd::ShowWindow(SW_SHOW)来显C对话框Q而不对话框是否hVisible风格?br>? 非模态对话框对象是用new操作W来动态创建的Q而不是以成员变量的Ş式嵌入到别的对象中或以局部变量的形式构徏的。通常应在对话框的拥有者窗口类内声明一个指向对话框cȝ指针成员变量Q通过该指针可讉K对话框对象?br>? 通过调用CDialog::Create函数来启动对话框Q而不是CDialog::DoModalQ这是两者之间区别的关键所在。由于Create函数不会启动新的消息循环Q对话框与应用程序共用同一个消息@环,q样对话框就不会垄断用户输入。Create在显CZ对话框后q卌回,而DoModal是在对话框被关闭后才q回的。由于在Createq回后,不能定对话框是否已关闭Q这样也无法确定对话框对象的生存期Q因此只好在堆栈中构建对话框对象Q而不能以局部变量的形式来构Z?br>? 必须调用CWnd::DestroyWindow而不是CDialog::EndDialog来关闭非模态对话框。调用CWnd::DestroyWindow是直接删除窗口的一般方法。由于缺省的CDialog::OnOK和CDialog::OnCancel函数均调用EndDialogQ故E序员必ȝ写自qOnOK和OnCancel函数q且在函C调用DestroyWindow来关闭对话框?br>? 因ؓ是用new操作W构建非模态对话框对象Q因此必d对话框关闭后Q用delete操作W删除对话框对象。在屏幕上一个窗口被删除后,框架会调用CWnd::PostNcDestroyQ这是一个虚拟函敎ͼE序可以在该函数中完成删除窗口对象的工作Q具体代码如?br>void CModelessDialog::PostNcDestroy
{delete this;    //删除对象}
q样Q在删除屏幕上的对话框后Q对话框对象被自动删除。拥有者就不必昑ּ地调用delete来删除对话框对象了?br>? 必须有一个标志表明非模态对话框是否打开的。这样做的原因是用户有可能在打开一个模态对话框的情况下Q又一ơ选择打开命o。程序根据标志来军_是打开一个新的对话框Q还是仅仅把原来打开的对话框ȀzR通常可以用拥有者窗口中的指向对话框对象的指针作U标志,当对话框关闭Ӟl该指针赋NULL|以表明对话框对象已不存在了?br>例如Q?br>创徏模态对话框
CTestDlg dlg;
dlg.DoModal();
创徏非模态对话框
CTestDlg * dlg = new CTestDlg;
dlg->Create(IDD_TEST_DLG);
dlg->ShowWindow(SW_SHOW);

 



isabc 2009-06-23 13:49 发表评论
]]>
XML字符串的d操作函数及示例程序[转]http://www.shnenglu.com/Lee7/archive/2009/06/22/88306.htmlisabcisabcMon, 22 Jun 2009 10:01:00 GMThttp://www.shnenglu.com/Lee7/archive/2009/06/22/88306.htmlhttp://www.shnenglu.com/Lee7/comments/88306.htmlhttp://www.shnenglu.com/Lee7/archive/2009/06/22/88306.html#Feedback1http://www.shnenglu.com/Lee7/comments/commentRss/88306.htmlhttp://www.shnenglu.com/Lee7/services/trackbacks/88306.html// OpXML.cpp : Defines the entry point for the console application.

//----------------------- Coded By Ronk --------------------------//
//----------------------- 2005-07-17 --------------------------//


#include 
"stdafx.h"
#include 
<stdio.h>


//---You must Setup the MSXML4.0 before using
#import <msxml4.dll>
using namespace MSXML2;

void xmlread(char *ch1,char *ch2,char *ch3);//Read the xmlstr and Get the Text of the Element

void xmlupdate(char *ch1,char *ch2,char *ch3);//Read the xmlstr and Update the Text of the Element

int main(int argc, char* argv[])
{
    
char xmlstr[1024]="<inesmsg><msghead><version>LZD</version><root>ioio</root></msghead></inesmsg>";
    
char strele[1024]="//version//";
    
char textstr[1024]="NNYX";
    
char value[1024];
    
    printf(
"The xmlstr is :\n%s\n\n",xmlstr);
    
    xmlread(xmlstr,strele,value); 
//befor Update
    printf("The Text of Element befor Update is: \n%s\n\n",value);
    
    xmlupdate(xmlstr,strele,textstr);
//Change the Text of "<version>" with "NNYX"
    printf("The Updated xmlstr is :\n%s\n\n",xmlstr);
    
    xmlread(xmlstr,strele,value);
//after Update
    printf("The Text of Element after Update is :\n%s\n\n",value);
    
    
return 0;
}

void xmlread(char* msgstr,char* elestr,char *tex)
{
    
//Initialize
    CoInitialize(NULL);
    
    IXMLDOMDocumentPtr pXmlDoc;
    IXMLDOMNodePtr pXmlNode;
    
    HRESULT hr;
    hr 
= pXmlDoc.CreateInstance(__uuidof(DOMDocument));
    
if (FAILED(hr))
    {
        printf(
"Faild to Create XMLDom Instance !");
        pXmlDoc
=NULL;
    }
    
else
    {
        pXmlDoc 
->async = VARIANT_FALSE;
        
        
//Load xmlmsg
        _bstr_t xmlstr=(LPCSTR)msgstr;
        
        
if (!(pXmlDoc->loadXML(msgstr)))
        {
            printf(
"Failed to Load xmlstr:\n%s\n",(LPCSTR)pXmlDoc->parseError->Getreason());
            pXmlDoc
=NULL;
        }
        
else
        {
            
//Locate the Element
            _bstr_t str=(LPCSTR)elestr;
            pXmlNode 
= pXmlDoc ->selectSingleNode(elestr);
            
            
if(FAILED(pXmlNode))
                printf(
"Faild to Locate the Element \n%s\n",str);
            
else
            {
                
//Read the Text of Element
                strcpy(tex,(LPCSTR)pXmlNode ->text);
                
                
//Realese
                pXmlDoc.Release();
                pXmlNode.Release();
            }
        }
    }
}

void xmlupdate(char *msgstr,char *elestr,char *upstr)
{
    
//---Initialize
    CoInitialize(NULL);
    
    IXMLDOMDocumentPtr pXmlDoc;
    IXMLDOMNodePtr pXmlNode;
    
    HRESULT hr;
    hr 
= pXmlDoc.CreateInstance(__uuidof(DOMDocument));
    
if (FAILED(hr))
    {
        printf(
"Faild to Create XMLDom Instance !");
        pXmlDoc
=NULL;
    }
    
else
    {
        pXmlDoc 
->async = VARIANT_FALSE;
        
        
//Load xml str
        _bstr_t xmlstr=(LPCSTR)msgstr;
        
        
if (!(pXmlDoc->loadXML(msgstr)))
        {
            printf(
"Failed to load xmlstr:\n%s\n",(LPCSTR)pXmlDoc->parseError->Getreason());
            pXmlDoc
=NULL;
        }
        
else
        {
            
//Located the Element
            _bstr_t str=(LPCSTR)elestr;
            pXmlNode 
= pXmlDoc ->selectSingleNode(elestr);
            
            
if (FAILED(pXmlNode))
                printf(
"Failed to Locate the Element \n%s\n",str);
            
else
            {
                
//Update the Text of the Element
                pXmlNode->text = upstr;
                
                
//Get the New xmlstr
                strcpy(msgstr,(LPCSTR)pXmlDoc->xml);
                
                
//Realese
                pXmlDoc.Release();
                pXmlNode.Release();
            }
        }
    }
}



isabc 2009-06-22 18:01 发表评论
]]>
99þþƷëƬѲ| þþƷר | ھƷþþþӰԺ޹²| AëƬþþþƷëƬ| ˹ھƷþþþһ| ճˮþ޾Ʒtv| ھƷþþþav| ŷһþþþþþô| þþƷһ| þþþAVվ | 99ŷƷþþѿ| ҹƷþþþ9999| þ99ƷþֻоƷ| þþƷƵһ| þþƷƷ| ˾þü91| 99ξþþŷƷվ| þۺɫHEZYO| ɫۺϾþۺ| Ʒþþþþ| ˾þþƷavһ| ŷҹAŴƬþ| þùƷҰAV| þݹֻƬ | ҹƷþ| þþþþþþ뾫Ʒպ| ޹㽶þþþþ| ƷۺרƬþþ | Ժձһձþ| þþþavר| þĻ| ˺ݺۺ88ۺϾþ| רþ| þþžžþƷֱ| þþƷWWW456C0M| þ۲ӰԺѿҹɫ| þþ| þþƷۺһ| 㽶aaþëƬ| þþ| þþþһƷɫav|