<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>庆亮的博客-webgame架构 &#187; 粘包</title>
	<atom:link href="http://www.qingliangcn.com/tag/%e7%b2%98%e5%8c%85/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.qingliangcn.com</link>
	<description>关注LAMP&#124;PHP源代码分析&#124;web架构&#124;PHP扩展&#124;Erlang&#124;服务端架构</description>
	<lastBuildDate>Fri, 10 Jun 2011 04:10:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Erlang中粘包处理</title>
		<link>http://www.qingliangcn.com/2010/01/erlang%e4%b8%ad%e7%b2%98%e5%8c%85%e5%a4%84%e7%90%86-2/</link>
		<comments>http://www.qingliangcn.com/2010/01/erlang%e4%b8%ad%e7%b2%98%e5%8c%85%e5%a4%84%e7%90%86-2/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 12:53:15 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[粘包]]></category>

		<guid isPermaLink="false">http://www.nd21.com/2010/01/erlang%e4%b8%ad%e7%b2%98%e5%8c%85%e5%a4%84%e7%90%86-2/</guid>
		<description><![CDATA[erlang中快速简单的处理粘包问题。]]></description>
			<content:encoded><![CDATA[<div class="Section0">
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt">&nbsp;</p>
<div class="Section0">
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span class="Apple-style-span" style="font-size: 13px"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'">开始时用的传统思路（循环读取）：</span><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span class="Apple-style-span" style="font-size: 13px"><span style="font-family: '宋体'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span class="Apple-style-span" style="font-size: 13px"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">recv(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">ClientSock</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLenOld</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Remain</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span class="Apple-style-span" style="font-size: 13px"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">when</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;is_integer(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLenOld</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">and</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;is_binary(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Remain</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; background: rgb(192,192,192); color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">gen_tcp:recv</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">ClientSock</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(90,90,180); font-size: 10pt; mso-spacerun: 'yes'">0</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{ok,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">B</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Bin</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;&lt;&lt;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Remain</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">/binary,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">B</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">/binary&gt;&gt;,</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(178,34,34); font-size: 10pt; mso-spacerun: 'yes'">%%&nbsp;read&nbsp;the&nbsp;packet&nbsp;length</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">if</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLenOld</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;=:=&nbsp;</span><span style="font-family: 'courier new'; color: rgb(90,90,180); font-size: 10pt; mso-spacerun: 'yes'">0</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">andalso</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;erlang:byte_size(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Bin</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)&nbsp;&gt;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(90,90,180); font-size: 10pt; mso-spacerun: 'yes'">2</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;-&gt;&nbsp;&lt;&lt;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLen</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">:</span><span style="font-family: 'courier new'; color: rgb(90,90,180); font-size: 10pt; mso-spacerun: 'yes'">16</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Remain2</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">/binary&gt;&gt;&nbsp;=&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Bin</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;true&nbsp;-&gt;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Remain2</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Bin</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLen</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLenOld</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10pt; mso-spacerun: 'yes'">?DEBUG</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'courier new'; color: rgb(188,143,143); font-size: 10pt; mso-spacerun: 'yes'">&quot;packet&nbsp;length&nbsp;~p&quot;</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLen</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">]),</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">if</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">erlang:byte_size(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Remain2</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)&nbsp;&gt;=&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLen</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;&nbsp;-&gt;&nbsp;{</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">RealData</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Next</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}&nbsp;=&nbsp;split_binary(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Remain2</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLen</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">MainData</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;decode(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">RealData</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;{ok,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">MainData</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(90,90,180); font-size: 10pt; mso-spacerun: 'yes'">0</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Next</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">};</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">true&nbsp;-&gt;&nbsp;{continue,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLen</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Remain2</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{error,&nbsp;closed}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10pt; mso-spacerun: 'yes'">?DEBUG</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'courier new'; color: rgb(188,143,143); font-size: 10pt; mso-spacerun: 'yes'">&quot;socket&nbsp;closed&nbsp;~p&nbsp;~n&quot;</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">ClientSock</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">]),</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{error,&nbsp;closed};</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{error,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10pt; mso-spacerun: 'yes'">?ERROR_MSG</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'courier new'; color: rgb(188,143,143); font-size: 10pt; mso-spacerun: 'yes'">&quot;socket&nbsp;closed&nbsp;~p&nbsp;with&nbsp;reason:&nbsp;~p&nbsp;~n&quot;</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">ClientSock</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">]),</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{error,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'times new roman'; font-size: 10pt; mso-spacerun: 'yes'">翻了翻文档发现实际上在erlang中没有必要这样麻烦</span><span style="font-family: 'times new roman'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'times new roman'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'verdana'; background: rgb(255,255,0); font-size: 10.5pt; mso-spacerun: 'yes'">The&nbsp;</span><span style="font-family: 'courier'; background: rgb(255,255,0); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">Length</span><span style="font-family: 'verdana'; background: rgb(255,255,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;argument&nbsp;is&nbsp;only&nbsp;meaningful&nbsp;when&nbsp;the&nbsp;socket&nbsp;is&nbsp;in&nbsp;</span></font></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier'; background: rgb(255,255,0); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">raw</span><span style="font-family: 'verdana'; background: rgb(255,255,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;mode&nbsp;and&nbsp;denotes&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read.&nbsp;</span></font></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'verdana'; background: rgb(255,255,0); font-size: 10.5pt; mso-spacerun: 'yes'">If&nbsp;</span><span style="font-family: 'courier'; background: rgb(255,255,0); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">Length</span><span style="font-family: 'verdana'; background: rgb(255,255,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;0,&nbsp;all&nbsp;available&nbsp;bytes&nbsp;are&nbsp;returned.&nbsp;</span></font></p>
<p class="p0" style="margin-top: 5pt; margin-bottom: 5pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'verdana'; background: rgb(255,255,0); font-size: 10.5pt; mso-spacerun: 'yes'">If&nbsp;</span><span style="font-family: 'courier'; background: rgb(255,255,0); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">Length</span><span style="font-family: 'verdana'; background: rgb(255,255,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&gt;&nbsp;0,&nbsp;exactly&nbsp;</span><span style="font-family: 'courier'; background: rgb(255,255,0); font-size: 10.5pt; font-weight: normal; mso-spacerun: 'yes'">Length</span><span style="font-family: 'verdana'; background: rgb(255,255,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;bytes&nbsp;are&nbsp;returned,&nbsp;or&nbsp;an&nbsp;error;</span><span style="font-family: 'verdana'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: '宋体'; color: rgb(0,0,255); font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">recv(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">ClientSock</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;gen_tcp:recv(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">ClientSock</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(90,90,180); font-size: 10pt; mso-spacerun: 'yes'">2</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{ok,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLenBin</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}&nbsp;-&gt;&nbsp;&lt;&lt;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLen</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">:</span><span style="font-family: 'courier new'; color: rgb(90,90,180); font-size: 10pt; mso-spacerun: 'yes'">16</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&gt;&gt;&nbsp;=&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLenBin</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">&nbsp;gen_tcp:recv(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">ClientSock</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">PacketLen</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{ok,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">RealData</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10pt; mso-spacerun: 'yes'">?DEBUG</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'courier new'; color: rgb(188,143,143); font-size: 10pt; mso-spacerun: 'yes'">&quot;recv&nbsp;data&nbsp;~p&quot;</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">RealData</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">]),</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{ok,&nbsp;decode(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">RealData</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">)};</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{error,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10pt; mso-spacerun: 'yes'">?ERROR_MSG</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'courier new'; color: rgb(188,143,143); font-size: 10pt; mso-spacerun: 'yes'">&quot;read&nbsp;packet&nbsp;data&nbsp;failed&nbsp;with&nbsp;reason:&nbsp;~p&quot;</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">]),</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{error,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">;</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{error,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}&nbsp;-&gt;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; text-indent: 36pt; margin-bottom: 0pt; margin-left: 72pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10pt; mso-spacerun: 'yes'">?ERROR_MSG</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">(</span><span style="font-family: 'courier new'; color: rgb(188,143,143); font-size: 10pt; mso-spacerun: 'yes'">&quot;read&nbsp;packet&nbsp;length&nbsp;failed&nbsp;with&nbsp;reason:&nbsp;~p&quot;</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">,&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">]),</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">{error,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10pt; mso-spacerun: 'yes'">}</span><span style="font-family: 'courier new'; font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><font class="Apple-style-span" face="宋体" size="3"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10pt; mso-spacerun: 'yes'"><o:p></o:p></span></font></p>
</p></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2010/01/erlang%e4%b8%ad%e7%b2%98%e5%8c%85%e5%a4%84%e7%90%86-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>


