<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[Linux下实现RPC编程]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Sat, 15 Jan 2011 16:07:27 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	Linux 下面使用RPC需要使用到命令rpcgen.<br/>在Linux下开发RPC程序流程如下：<br/>1.写一个rpc程序<br/>&nbsp;&nbsp;&nbsp;&nbsp;如test.x<br/>2.使用rpcgen生成必须的文件，通常是客户端和服务器端以及头文件<br/>&nbsp;&nbsp;&nbsp;&nbsp;$rpcgen test.x<br/>3.使用rpcgen生成服务器端和客户端的C语言代码<br/>&nbsp;&nbsp;&nbsp;&nbsp;$rpcgen -Ss -o test_server.c test.x<br/>&nbsp;&nbsp;&nbsp;&nbsp;$rpcgen -Sc -o test_client.c test.x<br/>4.生成Makefile<br/>&nbsp;&nbsp;&nbsp;&nbsp;$rpcgen -Sm test.x&gt;Makefile<br/>5.编辑源文件，加入你想要的服务等<br/>6.编辑Makefile,这很重要！<br/>7.执行测试<br/><br/>问题：<br/>1.服务器无法启动，错误如下：<br/>Cannot register service: RPC: Unable to receive; errno = Connection refused<br/>unable to register (TESTPROG, VERSION, udp).<br/>安装完rstatd后，为什么启动不了RPC?<br/><br/>提示：Cannot register service: RPC: Unable to receive; errno = Connection refused<br/><br/>这是因为你的服务器没有开启端口映射的功能。今天把这个问题的解决方法写下来，希望对有类似问题的朋友有所帮助。<br/><br/>[root@codebreaker]#setup<br/><br/>&nbsp;&nbsp; 这时会弹出一个类似图形化的界面，光标移动到System services，回车。在新界面中找到portmap项，空格选中。然后选择OK，再选择quit。<br/><br/>[root@codebreaker]#/etc/rc.d/init.d/portmap start&nbsp;&nbsp; //启动portmap<br/><br/>现在再试下rpc.rstatd？<br/><br/>====================================<br/><br/><br/>解决方法：系统没有安装portmap或者没有启动portmap端口映射。<br/>$ls /etc/init.d/&nbsp;&nbsp;&nbsp;&nbsp;<br/>如果没有portmap则安装之<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sudo apt-get install portmap<br/>如果有了，则启动<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sudo /etc/init.d/portmap start<br/>还可以使用chkconfig设置系统开机启动的服务项，如将portmap加入开机启动：<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sudo chkconfig --level 2 -s portmap on<br/><br/>下面是开发一个rpc程序的具体流程，详见<br/>http://zhoulifa.bokee.com/6128714.html<br/>我在编程中遇到以下几个问题：<br/>1.MySQL数据库错误<br/>&nbsp;&nbsp;&nbsp;&nbsp;1）报告连接不上MySQL，代码如下<br/>if(mysql_real_connect(conn,&quot;127.0.0.1&quot;,&quot;root&quot;,&quot;password&quot;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&quot;database&quot;,0,NULL,0))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&quot;%s&#92;n%s&#92;n&quot;,mysql_error(conn),<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;数据库连接失败&quot;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;exit(1);<br/>&#125;<br/>原因如下：判断语句错误，应该为if(mysql_real_connect(conn,...)==NULL)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;...<br/>&#125;<br/>2.更新数据失败<br/>&nbsp;&nbsp;&nbsp;&nbsp;char *sql=&quot;update test_table set balance=1000 where id=1000&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;result=mysql_query(conn,sql);<br/>&nbsp;&nbsp;&nbsp;&nbsp;if(result==NULL)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.....<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*错误*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>原因如下：还是判断语句错误，由于更新操作不向查询select操作，如果成功也是返回NULL，所以这里不需要判断result==NULL，其实这时数据库中的结果已经被更新了。<br/>3.RPC源文件test.x书写不当，但是我的程序已经基本实现了，这是怎么办？<br/>&nbsp;&nbsp;&nbsp;&nbsp;第一次声明test.x时就把函数完全声明正确有一点困难，所以出错在所难免，修改程序也很方便，首先，函数定义和声明（举例客户端）在 test_clnt.c，bank.h以及test_client.c（假设这个是你自己实现的客户端），只要修改这三个文件即可。<br/><br/>来源：http://blog.csdn.net/leisure512/archive/2009/11/11/4799328.aspx
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] Linux下实现RPC编程]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>