<?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>$i-&#62;php(); &#187; projectdarkstar</title>
	<atom:link href="http://i-php.net/tag/projectdarkstar/feed/" rel="self" type="application/rss+xml" />
	<link>http://i-php.net</link>
	<description>Hãy tiết kiệm điện và sử dụng opensource để bảo vệ môi trường</description>
	<lastBuildDate>Fri, 26 Feb 2010 07:29:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Project Dark Star &#8211; connecting server and client</title>
		<link>http://i-php.net/2009/03/project-dark-star-connect/</link>
		<comments>http://i-php.net/2009/03/project-dark-star-connect/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 21:37:08 +0000</pubDate>
		<dc:creator>dungbk</dc:creator>
				<category><![CDATA[projectdarkstar]]></category>

		<guid isPermaLink="false">http://i-php.net/?p=382</guid>
		<description><![CDATA[Ở bài tut trước đã hướng dẫn cách để làm cho Server “chạy”. Mục tiêu tiếp theo sẽ là làm sao để Server nói chuyện với Client, phức tạp hơn là làm cho các Client nói chuyện với nhau thông qua Server. Bài tut này sẽ hướng dẫn cách làm cho Server &#38; Client nói [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Ở bài tut trước đã hướng dẫn cách để làm cho Server “chạy”. Mục tiêu tiếp theo sẽ là làm sao để Server nói chuyện với Client, phức tạp hơn là làm cho các Client nói chuyện với nhau thông qua Server. Bài tut này sẽ hướng dẫn cách làm cho Server &amp; Client nói chuyện với nhau.</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Cụ tỉ sẽ gồm các công việc sau:</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial"><span style="mso-list: Ignore"><span style="font-size: small;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Start Server</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial"><span style="mso-list: Ignore"><span style="font-size: small;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Login: Start Client &amp; client login vào server, Server cho client login vào</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial"><span style="mso-list: Ignore"><span style="font-size: small;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Echo : Client gửi cho Server 1 chuỗi bất kì, Server gửi trả cho Client đúng chuỗi đó </span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="font-size: small;"><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 'Arial','sans-serif'">1. Start Server </span></strong><span style="FONT-FAMILY: Wingdings; mso-bidi-font-family: Arial; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">:</span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"> xem bài <a href="http://i-php.net/2009/03/darkstar-project/">tut</a> trước hoặc bài <a href="http://i-php.net/2009/03/project-dark-star-%E2%80%93-start-server-helloworld/">này</a><br />
</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="font-size: small;"><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 'Arial','sans-serif'">2. Login</span></strong><span style="FONT-FAMILY: 'Arial','sans-serif'">: </span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial"><span style="mso-list: Ignore"><span style="font-size: small;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Tạo một project mới quản lý Client, ví dụ tên là PDSHelloClient. </span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><span style="mso-list: Ignore"><span style="font-size: small;">o</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Add các file .jar trong <em>\sgs-client-0.9.8\lib</em> theo cách tương tự như đã làm với Server</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><span style="mso-list: Ignore"><span style="font-size: small;">o</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Tạo 1 package mới và copy file HelloUserClient.java trong <em>\sgs-client-0.9.8\tutorial\src\com\sun\sgs\tutorial\client\lesson1 </em>vào.</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial"><span style="mso-list: Ignore"><span style="font-size: small;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Quay về project Server: </span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><span style="mso-list: Ignore"><span style="font-size: small;">o</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Copy class HelloUserSessionListener ở <em>\sgs-server-dist-0.9.8\tutorial\src\com\sun\sgs\tutorial\server\lesson5.</em></span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><span style="mso-list: Ignore"><span style="font-size: small;">o</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Trong class của Server: </span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">- Thêm khai báo logger:</span></span></p>
<blockquote>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">/** The {@link Logger} for this class. */<br />
private static final Logger logger =<br />
Logger.getLogger(HelloWorld.class.getName());<br />
</span></span></p></blockquote>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">- đổi phương thức </span></span><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">loggedIn</span></strong><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;"><strong><span style="font-size: x-small; color: #7f0055; font-family: Courier New;"> </span></strong>thành:</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">public ClientSessionListener loggedIn(ClientSession session) {</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>// User has logged in</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>logger.log(Level.INFO, &#8220;User {0} has logged in&#8221;, session.getName());</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"> </span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>// Return a valid listener</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>return new HelloUserSessionListener(session);</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>}</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Để server cho phép Client login và log lại thông tin. Phương thức này sẽ trả về một instance của </span></span><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">HelloUserSessionListener.</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">(Hoặc copy Class HelloEcho trong \sgs-server-dist-0.9.8\tutorial\src\com\sun\sgs\tutorial\server\lesson5 )<br />
</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial"><span style="mso-list: Ignore"><span style="font-size: small;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Bây giờ Run lại Server &amp; Run Client, xong nhiệm vụ 2</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="font-size: small;"><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 'Arial','sans-serif'">3. Echo</span></strong><span style="FONT-FAMILY: 'Arial','sans-serif'">:</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial"><span style="mso-list: Ignore"><span style="font-size: small;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Phía Server:</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><span style="mso-list: Ignore"><span style="font-size: small;">o</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Copy class HelloEchoSessionListener từ <em>\sgs-server-dist-0.9.8\tutorial\src\com\sun\sgs\tutorial\server\lesson5.</em></span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><span style="mso-list: Ignore"><span style="font-size: small;">o</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Trong class của Server: đổi phương thức <strong></strong></span></span><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">loggedIn</span></strong><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;"><strong><span style="font-size: x-small; color: #7f0055; font-family: Courier New;"> </span></strong>thành:</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">public ClientSessionListener loggedIn(ClientSession session) {</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>// User has logged in</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>logger.log(Level.INFO, &#8220;User {0} has logged in&#8221;, session.getName());</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"> </span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>// Return a valid listener</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>return new HelloEchoSessionListener(session);</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in"><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"><span style="mso-spacerun: yes"> </span>}</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in"><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Khác biệt duy nhất ở đây so với phương thức </span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"></span><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">loggedIn</span></strong><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;"><strong><span style="font-size: x-small; color: #7f0055; font-family: Courier New;"> </span></strong></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">cũ là phương thức này trả về một instance của</span></span><strong><span style="FONT-SIZE: 10pt; COLOR: #7f0055; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'"> HelloEchoSessionListener</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1"><span style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><span style="mso-list: Ignore"><span style="font-size: small;">o</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Bây giờ Run Server đi.</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"><span style="FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: Arial"><span style="mso-list: Ignore"><span style="font-size: small;">-</span><span style="FONT: 7pt 'Times New Roman'"> </span></span></span><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Phía Client: Run Client và type vào text box một string bất kì, sẽ nhận được phản hồi từ phía Server.</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 10pt"><span style="FONT-FAMILY: 'Arial','sans-serif'"><span style="font-size: small;">Xong. Bây giờ tìm cách để Client trò chuyện với Client đi <img src='http://i-php.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://i-php.net/2009/03/project-dark-star-connect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
