<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5786214393214651277</id><updated>2012-02-10T11:04:58.073-05:00</updated><category term='MozillaBuild'/><category term='race condition'/><category term='poll()'/><category term='B3G'/><category term='SpiderMonkey'/><category term='fork()'/><category term='Foreign Agent'/><category term='OFDM'/><category term='critical section'/><category term='embedded programming'/><category term='Home Agent'/><category term='Wibro'/><category term='3G'/><category term='MAC'/><category term='pthread'/><category term='Rhino'/><category term='mutex'/><category term='3GPP'/><category term='wikimedia'/><category term='WiMAX'/><category term='semaphore'/><category term='MIMO'/><category term='linux'/><category term='4G'/><category term='UMB'/><category term='Wi-Fi'/><category term='select()'/><category term='Javascript'/><category term='UMTS'/><category term='WPA'/><category term='sockets'/><category term='Mobile TV'/><category term='Fedora 9'/><category term='algorithm'/><category term='thread'/><category term='2G'/><category term='Open Source'/><category term='VMware Tools'/><category term='cyclic prefix'/><category term='wikipedia'/><category term='Care-Of Address'/><category term='cdma2000'/><category term='POSIX'/><category term='WEP'/><category term='QoS'/><category term='VMware'/><category term='802.11'/><category term='wireless'/><category term='LTE'/><category term='TD-SCDMA'/><category term='OFDMA'/><category term='Mobile IP'/><category term='WCDMA'/><category term='in-place'/><title type='text'>Taking Technology to the MAX</title><subtitle type='html'>Since we cannot know all that is to be known of everything, we ought to know a little about everything. 
                                    ---Blaise Pascal.
&lt;br&gt;
Success is built up of failures as a house is built of stones, but an accumulation of failures is no more a success than a heap of stones is a house.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>44</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-3769993541789484089</id><published>2009-12-24T13:08:00.007-05:00</published><updated>2009-12-24T13:21:47.213-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='wikipedia'/><category scheme='http://www.blogger.com/atom/ns#' term='wikimedia'/><title type='text'>Do what I can do for wikipedia</title><content type='html'>Imagine a world in which every single person on the planet has free access to the sum of all human knowledge. That’s where we’re headed. And with your help, we will get there.  -- Jimmy Wales&lt;br /&gt;&lt;br /&gt;I use Wikipedia almost everyday. I love it, so I do what I can do. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thank you for your gift of USD 35.00 to the Wikimedia Foundation,&lt;br /&gt;received on December 24, 2009.&lt;br /&gt;&lt;br /&gt;Your donation celebrates everything Wikipedia stands for: the power of&lt;br /&gt;information, freedom, sharing, learning and discovery.   Thank you so&lt;br /&gt;much for helping keep Wikipedia freely available for its 330 million&lt;br /&gt;readers around the world.&lt;br /&gt;&lt;br /&gt;Many people love Wikipedia, but surprisingly few know it's run by a&lt;br /&gt;non-profit.  Please help us spread the word, by forwarding this e-mail&lt;br /&gt;to a few of your friends.&lt;br /&gt;&lt;br /&gt;If you have questions about your donation, please send a message to&lt;br /&gt;donate@wikimedia.org.  To learn more about the Wikimedia Foundation,&lt;br /&gt;visit our blog at http://blog.wikimedia.org/ or our website at&lt;br /&gt;http://wikimediafoundation.org/. Or, follow us at&lt;br /&gt;http://twitter.com/wikimedia, http://identi.ca//wikimedia, or&lt;br /&gt;http://bit.ly/wikiFacebook.&lt;br /&gt;&lt;br /&gt;And again, thank you.  I'm really, really happy to have&lt;br /&gt;your help.&lt;br /&gt;&lt;br /&gt;Sincerely Yours,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sue Gardner&lt;br /&gt;Executive Director, Wikimedia Foundation&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-3769993541789484089?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/3769993541789484089/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=3769993541789484089' title='64 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3769993541789484089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3769993541789484089'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2009/12/do-what-i-can-do-for-wikipedia.html' title='Do what I can do for wikipedia'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>64</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-5794124144691879889</id><published>2009-03-23T01:11:00.021-04:00</published><updated>2009-03-23T02:40:29.068-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCDMA'/><category scheme='http://www.blogger.com/atom/ns#' term='2G'/><category scheme='http://www.blogger.com/atom/ns#' term='TD-SCDMA'/><category scheme='http://www.blogger.com/atom/ns#' term='cdma2000'/><category scheme='http://www.blogger.com/atom/ns#' term='3G'/><title type='text'>[Wireless] Three kingdoms in China mobile market</title><content type='html'>If you recently watched the movie &lt;a href="http://www.imdb.com/title/tt1326972/"&gt;"Red Cliff"&lt;/a&gt; directed by John Woo, you would know it is a story about a battle of the Three Kingdoms period in the history of China. Although this period is relatively short, it has been greatly romanticised in the cultures of China. Any Chinese people knows a bunch of legends of those three kingdoms (Cao Wei, Shu Han, and Dong Wu). By coincidence, currently there are three big mobile communication companies in China, they are China Mobile, China Unicom and China Telcom. Those three companies compete one another for the China mobile market, which is very similar to those three kingdoms combated for the territory. &lt;br /&gt;&lt;br /&gt;Previously, only China Mobile and China Unicom own the operating license for 2G mobile systems in China. At that time, although China Unicom was considered as a competitor of China Mobile, it was still too weak to jeopardize China Mobile's dictatorial control of the mobile market. And China Telecom only has the largest wiring system and has been wishing for the mobile license for a very long time. In order to expediate the development of 3G systems, and to change the unbalanced competition pattern as well, in Jan 2009 China's Ministry of Industry and Information Technology issued 3G licenses to those three companies. China Mobile got TD-SCDMA, China Unicom will develop WCDMA and China Telecom has the grant for CDMA2000. &lt;br /&gt;&lt;br /&gt;Technically, China Unicom benefits a lot from 3G license since WCDMA is the most mature system; China Telecom also got they desired - the mobile license; and China Mobile will face a fiercer competition from the other two companies since TD-SCDMA is still "weaker" in the view of development. &lt;br /&gt;&lt;br /&gt;However, you have to take good with bad. China Unicom needs to spend a longer time and more efforts to integrate the WCDMA system into its own development. China Telecom lacks of mobile operating experience and cdma2000 has a dim future in 3G long term evolution. Although TD-SCDMA has no technology advantage, China Mobile has the largest 2G system in the world and has accumulated abundant operating experiences over years. &lt;br /&gt;&lt;br /&gt;It seems that 3 licenses for 3G is a good choice for competition pattern change. However, my question is, why 3? From the view of history, three kingdoms period is one of the most "bloody" period in China. In the pointview of market, competition of two is the most stable pattern. Because when you have two opponents, you may select one as your ally to combat the strongest. However, this confederation may be variant along with time. When the strongest becomes weak, it may ally with another opponent to conterwork you. This will fluctuate the market and may not be good for the whole industry's developing. Just my two cents. :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-5794124144691879889?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/5794124144691879889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=5794124144691879889' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/5794124144691879889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/5794124144691879889'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2009/03/wireless-three-kingdoms-in-china-mobile.html' title='[Wireless] Three kingdoms in China mobile market'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-3687687429666567788</id><published>2008-11-01T22:49:00.013-04:00</published><updated>2008-11-03T20:44:59.473-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VMware'/><category scheme='http://www.blogger.com/atom/ns#' term='Fedora 9'/><category scheme='http://www.blogger.com/atom/ns#' term='VMware Tools'/><title type='text'>[Software] Install VMware Tools on Fedora 9</title><content type='html'>I bought a new PC with Window XP operating system. Like what I did on my old computer, I decided to install VMware workstation on Windows XP since I also need Linux/Unix environment for software development. I downloaded Fedora 9 ISO image from redhat.com and used it to build the linux guest OS on the VMware workstation. Everything for Fedora 9 installation went smoothly. After that, I began to install VMware Tools as usual (you can find a guide from &lt;a href="http://www.vmware.com/support/ws5/doc/ws_newguest_tools_linux.html"&gt;VMware&lt;/a&gt;):&lt;br /&gt;&lt;br /&gt;1) Select "Install VMware tools" on VMware, it will mount VMware Tools to "/media/VMware Tools" of the guest Linux OS,&lt;br /&gt;2) start a terminal, type in "su", enter the root password,&lt;br /&gt;3) rpm -Uhv /media/VMware\ Tools/VMware*.rpm, install the VMware Tools using RPM (or you can use extract the gz file using tar). Note, there's a space between VMware and Tools, so you need a backslash,&lt;br /&gt;4) after installation, you should have a script file installed: /usr/bin/vmware-config-tools.pl&lt;br /&gt;5) run rmware-config-tools.pl, it will ask you several questions, such as "which compile command to use", "kernel headers directory" etc.&lt;br /&gt;&lt;br /&gt;However, when it goes to "kernel headers directory", it complained that the default directory /usr/src/include/linux does not exist or the kernel headers are not matched to the kernel you are running. In order to solve this problem, start a new terminal and run "rpm -qal | grep kernel", it will tell you what kernels have been  installed on your guest OS and where they are located (for my case, it's under /lib/modules/2.6.6.xxx/include). &lt;br /&gt;&lt;br /&gt;After changing the directory, it still doesn't work and continues complaining "mismatch" messages. The reason is that I upgraded the kernel but didn't reboot it. So the running kernel and the header files installed are not "synchronized" yet. Restart the OS and re-run vmware-config-tools.pl, now it's ok.&lt;br /&gt;&lt;br /&gt;The last step of vmware configure is to set the dispaly resolution. After that, you need to restart X as it suggests. Unfortunately, another problem emerged: the mouse position messed up. I clicked the menu but it's not selected. I googled this problem, and found it's a xorg-x11-drv-vmmouse driver bug for Fedora 9 only. A work around is given in this &lt;a href="http://docs.fedoraproject.org/release-notes/f9/en_US/sn-Desktop.html#vmmouse-driver"&gt;link&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;Edit /etc/X11/xorg.conf in the guest machine. Create the section if necessary:&lt;br /&gt;&lt;br /&gt;Section "ServerFlags"&lt;br /&gt; Option      "NoAutoAddDevices"&lt;br /&gt;EndSection&lt;br /&gt;&lt;br /&gt;Restart X, everything goes well! Now you can enjoy the features provided by VMware, such as copy&amp;paste between host and guest OSs, share files and folders etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-3687687429666567788?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/3687687429666567788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=3687687429666567788' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3687687429666567788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3687687429666567788'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/11/software-install-vmware-tools-on-fedora.html' title='[Software] Install VMware Tools on Fedora 9'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-4414498771277903707</id><published>2008-08-25T20:59:00.003-04:00</published><updated>2008-08-25T21:01:44.976-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='embedded programming'/><title type='text'>Embedded C programming - for beginners (1)</title><content type='html'>Here the beginner is me. :-) If you never touched embedded C programming before and want to learn it, join me. I have some experiences to share with you. We can teach and learn ourselves. &lt;br /&gt;&lt;br /&gt;Embedded programming is always hardware related. You may at least need to buy a develop kit or emulator. The price is not that cheap (usually costs you several hundred bucks, with those bucks you can send roses to your GF everyday for two months). Can we save those bucks and still learn the fundamentals of embedded C programming? Congratualtion, you got it!&lt;br /&gt;&lt;br /&gt;Thanks to Keil - An ARM company. If you never heared about Keil, congratulation again! you are the beginner and this article is right for you! Keil provides a great Evaluation Software supporting different paltforms but with very few limitations. It includes the assembler, compiler, linker, debugger, and IDE. Everything you need for embedded C learning is here. How to get it? Go to this webpage of Keil (&lt;a href="http://www.keil.com/demo/"&gt;http://www.keil.com/demo/&lt;/a&gt;) and you can get it free (you just need to fill out a simple form)!&lt;br /&gt;&lt;br /&gt;Ok, next I'll show you how to write your first embedded C program.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-4414498771277903707?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/4414498771277903707/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=4414498771277903707' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/4414498771277903707'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/4414498771277903707'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/08/embedded-c-programming-for-beginners-1.html' title='Embedded C programming - for beginners (1)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-1475136143728682226</id><published>2008-07-06T19:33:00.007-04:00</published><updated>2008-07-06T20:31:45.708-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Rhino'/><category scheme='http://www.blogger.com/atom/ns#' term='Open Source'/><category scheme='http://www.blogger.com/atom/ns#' term='MozillaBuild'/><category scheme='http://www.blogger.com/atom/ns#' term='SpiderMonkey'/><title type='text'>Run Javascript under Windows using Mozilla's interpreter - SpiderMonkey</title><content type='html'>Javascript is widely used in Web programming. Microsoft's Internet Explorer and Mozilla's Firefox both include its Javascript interpreter in the browsers. However, they also limit your capability of running Javascript in a web-only environment.  &lt;br /&gt;&lt;br /&gt;The good news is, Mozilla's interpreter was released as an open source. You can find it from &lt;a href="http://www.mozilla.org/js/"&gt;http://www.mozilla.org/js/&lt;/a&gt;. It has two versions, one is written in C and is called SpiderMonkey. The other is written in Java and called Rhino.&lt;br /&gt;&lt;br /&gt;Today, I installed SpiderMonkey on a windows xp computer. The installation is very simple:&lt;br /&gt;1) Install Mozilla Developer Center - &lt;a href="http://developer.mozilla.org/en/docs/Windows_Build_Prerequisites"&gt;MozillaBuild&lt;/a&gt;&lt;br /&gt;2) Go to SpiderMonkey's website to get the latestest version and &lt;a href="http://developer.mozilla.org/en/docs/SpiderMonkey_Build_Documentation"&gt;build it&lt;/a&gt; under MozillaBuild. &lt;br /&gt;&lt;br /&gt;After installation, you will get the executable interpreter js.exe in a directory whose name depends on the system you're building on (you can find this direcotry under mozilla/js/src/ with a suffix .OBJ). &lt;br /&gt;&lt;br /&gt;If you are not accustomed to the MozillaBuild environment (unix-like) and is comfortable with Windows/Dos, you can modify the system environment by adding the path of js.exe into the PATH variable (right click "My computer" in Windows Explorer, and then select  Advanced -&gt; Environment Variables). Then under the DOS prompt environment (in Windows, Start -&gt; Run -&gt; cmd) , you can use "js file.js" to run your javascripts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-1475136143728682226?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/1475136143728682226/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=1475136143728682226' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1475136143728682226'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1475136143728682226'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/07/run-javascript-under-windows-using.html' title='Run Javascript under Windows using Mozilla&apos;s interpreter - SpiderMonkey'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-6399943412761473546</id><published>2008-05-16T01:15:00.005-04:00</published><updated>2008-05-16T01:47:24.387-04:00</updated><title type='text'>Call for Donations for the China Eearthquake!</title><content type='html'>&lt;strong&gt;Sichuan Earthquake Facts&lt;/strong&gt;&lt;br /&gt;To date (May 15), 19,500 dead, and 80 percent of buildings toppled in one county &lt;br /&gt;Thousands buried in the rubble of collapsed buildings &lt;br /&gt;Chinese government estimates 4.9 million houses destroyed &lt;br /&gt;More than 60,000 people are "missing or out of reach" &lt;br /&gt;Rescuers digging through rubble to find survivors &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Donation websites:&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://www.mercycorps.org/chinaearthquake/"&gt;http://www.mercycorps.org/chinaearthquake/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://donate.ifrc.org/"&gt;http://donate.ifrc.org/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.redcross.org.hk/"&gt;http://www.redcross.org.hk/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;NPR's report (by Melissa Block)&lt;/strong&gt;&lt;br /&gt;Audio:&lt;br /&gt;&lt;a href="http://www.npr.org/templates/story/story.php?storyId=90447603"&gt;http://www.npr.org/templates/story/story.php?storyId=90447603&lt;/a&gt;&lt;br /&gt;then click on "Listen Now"&lt;br /&gt;&lt;br /&gt;Report:&lt;br /&gt;&lt;a href="http://www.npr.org/blogs/chengdu/2008/05/we_found_fu_guanyu_and.html#more"&gt;http://www.npr.org/blogs/chengdu/2008/05/we_found_fu_guanyu_and.html#more&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_bmgcIB-XFnQ/SC0c8LvA24I/AAAAAAAAACM/BljXxZADQQw/s1600-h/427ac9a649652c719cfdccc628d02533.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp3.blogger.com/_bmgcIB-XFnQ/SC0c8LvA24I/AAAAAAAAACM/BljXxZADQQw/s320/427ac9a649652c719cfdccc628d02533.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5200844964950498178" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_bmgcIB-XFnQ/SC0dLrvA25I/AAAAAAAAACU/BaMbsu_RM2g/s1600-h/3fd93318266f01bb2c9971ea097f71ce.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_bmgcIB-XFnQ/SC0dLrvA25I/AAAAAAAAACU/BaMbsu_RM2g/s320/3fd93318266f01bb2c9971ea097f71ce.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5200845231238470546" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_bmgcIB-XFnQ/SC0dMLvA26I/AAAAAAAAACc/JEtt3Hl0Cqs/s1600-h/b39e0f52b017ef1ebb42fb59ffc6118a.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp3.blogger.com/_bmgcIB-XFnQ/SC0dMLvA26I/AAAAAAAAACc/JEtt3Hl0Cqs/s320/b39e0f52b017ef1ebb42fb59ffc6118a.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5200845239828405154" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-6399943412761473546?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/6399943412761473546/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=6399943412761473546' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6399943412761473546'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6399943412761473546'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/05/call-for-donations-for-china.html' title='Call for Donations for the China Eearthquake!'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_bmgcIB-XFnQ/SC0c8LvA24I/AAAAAAAAACM/BljXxZADQQw/s72-c/427ac9a649652c719cfdccc628d02533.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-7564645610727844184</id><published>2008-04-08T19:43:00.006-04:00</published><updated>2008-04-15T22:03:03.769-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='race condition'/><category scheme='http://www.blogger.com/atom/ns#' term='thread'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='critical section'/><category scheme='http://www.blogger.com/atom/ns#' term='semaphore'/><category scheme='http://www.blogger.com/atom/ns#' term='mutex'/><title type='text'>[Programming] Threads (4) - synchronization</title><content type='html'>Threads (4) - synchronization&lt;br /&gt;&lt;br /&gt;Previously we described the issue of joinable and detached thread scheduling. In practice, the situation is not that simple. Most of the threaded programs are concurrent programs, which means the operating system will run multiple threads at the same time. However, there's no way to know when a thread will be scheduled to run by the system. The order of thread's running is not deterministic. &lt;br /&gt;&lt;br /&gt;Another big problem of threaded programming is that, unlike processes, threads share the same address space. This is one of the powerful aspects of threads - if one thread changes the value of a variable, other threads will see this modification subsequently. However, this sharing could also be dangerous without careful design and implemenation. &lt;br /&gt;&lt;br /&gt;The third thing is that debugging a threaded program is not easy as debugging a single-thread program - you may not reproduce the same result in a multi-threaded program. &lt;br /&gt;&lt;br /&gt;Therefore, the synchronization among threads is a very important issue. In order to understand the details of synchronization, let's first learn some new concepts one by one: critical section, atomic operation, race condition, mutex, semaphore, deadlock.&lt;br /&gt;&lt;br /&gt;&lt;font color=blue&gt;Critical section&lt;/font&gt;: it means a resource (usually implemented by a sequence of code) that should be exclusively used by a program for a period of its execution. In simple words, if a thread begins executing a critical section code, it must continue to the end without being canceled. &lt;br /&gt;&lt;br /&gt;&lt;font color=blue&gt;Race condition&lt;/font&gt;: since a critical section can only be exclusively used, when multi threads occur concurrently, they will compete for the critical section. In this situation, we say there is a race condition. &lt;br /&gt;&lt;br /&gt;In order to eliminate race conditions and ensure a critical section being implemented successfully, we need a way to make operations atomic, which is described below.  &lt;br /&gt;&lt;br /&gt;&lt;font color=blue&gt;Atomic operation&lt;/font&gt;: when we speak of an atomy, we usually mean that it is a tiny particle indivisible. So here the atomic operation has the similar meaning: once the operation starts, it will not be canceled, pasued or interrupted until it completes; at the meantime, no other operation will take place either.In multi-threaded programming, the operating system will provide and guarantee some operations to be atomic. &lt;br /&gt;&lt;br /&gt;(to be continued)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-7564645610727844184?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/7564645610727844184/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=7564645610727844184' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/7564645610727844184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/7564645610727844184'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/04/programming-threads-4-synchronization.html' title='[Programming] Threads (4) - synchronization'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-8625243643299079721</id><published>2008-04-02T14:22:00.007-04:00</published><updated>2008-04-15T22:10:37.209-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCDMA'/><category scheme='http://www.blogger.com/atom/ns#' term='TD-SCDMA'/><category scheme='http://www.blogger.com/atom/ns#' term='wireless'/><category scheme='http://www.blogger.com/atom/ns#' term='UMTS'/><category scheme='http://www.blogger.com/atom/ns#' term='cdma2000'/><category scheme='http://www.blogger.com/atom/ns#' term='3G'/><title type='text'>[Wireless] China 3G phone (TD-SCDMA)</title><content type='html'>In the area of 3G, China proposed and submitted its own standard (TD-SCDMA) to ITU-R in 1998 and got it approved as one of the 3G standardized technologies in the world. After that, China has been working on this standard for about 10 years. In order to support this self-own standard, China government postponed the 3G licence from year to year, and &lt;a href="http://www.chinamobile.com/en/"&gt;China Mobile Group&lt;/a&gt; (the world's largest mobile phone operator ranked by number of subscribers, with over 376.38 million customers by the end of Feb, 2008) was selected to build pre-commercial networks for TD-SCDMA system. Many of my previous colleagues in China participated in this project.&lt;br /&gt;&lt;br /&gt;Yesterday (Apr 1, 2008), a video clip about China 3G/TD-SCDMA phone was released in &lt;a href="http://www.sina.com.cn"&gt;sina.com&lt;/a&gt; (the largest Chinese-language infotainment web portal). In this clip, a video call, a piece of stream media and some java supported applications are demonstrated on a TD-SCDMA phone (the model is U980 of &lt;a href="http://wwwen.zte.com.cn/"&gt;ZTE&lt;/a&gt;). The video call looks not bad. Although UMTS (WCDMA), cdma2000 EVDO, and even HSDPA have been widely deployed by some service providers in the United states, as I know no one supports video call yet. &lt;br /&gt;&lt;br /&gt;The Olympics game is coming soon. Although China said TD-SCDMA might not make Olympics deadline, it's still very possible that TD-SCDMA phones will be offered on hand and showcased at that time. &lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="350"&gt; &lt;param name="movie" value="http://www.youtube.com/v/IzTzNNlbKzY"&gt; &lt;/param&gt; &lt;embed src="http://www.youtube.com/v/IzTzNNlbKzY" type="application/x-shockwave-flash" width="425" height="350"&gt; &lt;/embed&gt; &lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-8625243643299079721?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/8625243643299079721/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=8625243643299079721' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8625243643299079721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8625243643299079721'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/04/wireless-china-3g-phone-td-scdma.html' title='[Wireless] China 3G phone (TD-SCDMA)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-6079918468318108049</id><published>2008-03-31T19:51:00.014-04:00</published><updated>2008-04-15T22:04:43.344-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='thread'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='POSIX'/><title type='text'>[Programming] Threads (3) - joinable or detached thread</title><content type='html'>Last time we've seen it's very easy to create a new thread in Linux by using the POSIX thread API functino pthread_create(). But wait, that example code has a bug. How does Linux schedule those two threads, namely, the main thread and the new created thread? &lt;br /&gt;&lt;br /&gt;The answer is Nothing! If the new created thread terminates before the main thread, everything is ok. But it's very possible that the main thread stops first, especially when you are creating a new thread to do some time-cost calculation or operation. In this case, the memory used to passing parameters to thread function will be deallocated when the main thread is done, while the created thread may still be accessing this block of memory. &lt;br /&gt;&lt;br /&gt;So we need a mechanism to avoid this. The POSIX thread standard provides a function called &lt;font color=blue&gt;pthread_joint()&lt;/font&gt;. It's similar to the &lt;font color=blue&gt;wait()&lt;/font&gt; function that a parent process used to collect child processes. With pthread_join(), the main thread will wait until the new created thread terminates, then the main thread returns. In addition, the pthread_join() also provides a way for the main thread to read return values from the created thread. &lt;br /&gt;&lt;br /&gt;The prototype of pthread_join() is&lt;br /&gt;&lt;em&gt;&lt;font color=blue&gt;int pthread_join(pthread_t thread, void **thread_return);&lt;/font&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;pthread_join() looks good but it doesn't suit for all cases. Sometimes we may just want the main thread to call a new thread, but don't need the main thread to wait for the return of the new thread. For example, we create a second thread to print some documents. It's not necessary to let the main thread wait, it can continue to serve other jobs while the print is onging. In this situation, we can make the thread &lt;font color=red&gt;&lt;strong&gt;detached&lt;/strong&gt;&lt;/font&gt; instead of &lt;font color=red&gt;&lt;strong&gt;joinable&lt;/strong&gt;&lt;/font&gt;. In order to do this, we need to set the second argument in the pthread_create() function, i.e. &lt;font color=blue&gt;thread attributes&lt;/font&gt;.&lt;br /&gt;&lt;br /&gt;As we did in the previous blog, setting thread attributes to NULL means the default attribute (thread is joinable) is used. If we need detached thread, we can use &lt;font color=blue&gt;pthread_attr_init()&lt;/font&gt; function to initialize it, then call &lt;font color=blue&gt;pthread_attr_setdetachstate()&lt;/font&gt; to set the attribute as detached. Indeed, POSIX thread provides a set of functions to set different attributes to a thread, such as scheculed, inherited etc. But for most applications, the detached attribute is typically of interest.&lt;br /&gt;&lt;br /&gt;A typical program setting thread attributes to detached is as follows:&lt;br /&gt;&lt;br /&gt;&lt;div style="background:#c0c0c0;border-style:none;border-width:thin;"&gt;&lt;pre&gt;&lt;code&gt;&lt;font color="#000000" size=2&gt;&lt;font color="#0000ff"&gt;{&lt;/font&gt;&lt;br /&gt;   &lt;font color="#0000ff"&gt;...&lt;/font&gt;&lt;br /&gt;   pthread_attr_t threadAttr&lt;font color="#0000ff"&gt;;&lt;/font&gt;&lt;br /&gt;   pthread_t thread&lt;font color="#0000ff"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;   pthread_attr_init&lt;font color="#0000ff"&gt;(&amp;amp;&lt;/font&gt;threadAttr&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;   pthread_attr_setdetachstate&lt;font color="#0000ff"&gt;(&amp;amp;&lt;/font&gt;threadAttr&lt;font color="#0000ff"&gt;,&lt;/font&gt; PTHREAD_CREATE_DETACHED&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;   pthread_create&lt;font color="#0000ff"&gt;(&amp;amp;&lt;/font&gt;thread&lt;font color="#0000ff"&gt;, &amp;amp;&lt;/font&gt;threadAttr&lt;font color="#0000ff"&gt;,&lt;/font&gt; thread_function&lt;font color="#0000ff"&gt;, (&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;*)&lt;/font&gt;thread_arguments&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;   pthread_attr_destroy&lt;font color="#0000ff"&gt;(&amp;amp;&lt;/font&gt;threadAttr&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;   &lt;font color="#0000ff"&gt;...&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;}&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-6079918468318108049?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/6079918468318108049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=6079918468318108049' title='97 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6079918468318108049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6079918468318108049'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/03/programming-threads-3-joinable-or.html' title='[Programming] Threads (3) - joinable or detached thread'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>97</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-8759157412203975913</id><published>2008-03-20T17:54:00.007-04:00</published><updated>2008-04-15T22:05:37.129-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='pthread'/><category scheme='http://www.blogger.com/atom/ns#' term='thread'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='POSIX'/><title type='text'>[Programming] Threads (2) - Thread Creation</title><content type='html'>In Linux/Unix, threads are implemented using POSIX standard API (known as pthreads). All functions and data types related to threads are declared in the header file &lt;pthread.h&gt;. &lt;br /&gt;&lt;br /&gt;To create a thread, use the pthread_create() function. The prototype of pthread_create() is &lt;br /&gt;&lt;font color=blue&gt;#include &amp;lt;pthread.h&amp;gt;&lt;br /&gt;int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;The function is not hard to understand&lt;br /&gt;1) the first argument is used to store the thread ID of the new created thread&lt;br /&gt;2) the second argument is a pointer to a thread attribute object, you can use NULL as default or call pthread_attr_init() to initialize the attribue you want&lt;br /&gt;3) the third argument is a pointer to the thread function, i.e., the function used for the new created thread. Don't be scared by the format, it's just an ordinary function pointer.&lt;br /&gt;4) the last argument is used to pass parameters to the thread function, i.e. the thread function uses this passed value as its arguments&lt;br /&gt;&lt;br /&gt;We'll use a simple example to show how it works. The code with comments is attached below&lt;br /&gt;&lt;br /&gt;&lt;div style="background:#c0c0c0;border-style:none;border-width:thin;"&gt;&lt;pre&gt;&lt;br /&gt;&lt;font color="#000000" size =2&gt;&lt;br /&gt;&lt;font color="#800000"&gt;/** simple_thread.c */&lt;/font&gt;&lt;br /&gt;&lt;font color="#d70000"&gt;#include &amp;lt;pthread.h&amp;gt;&lt;br /&gt;#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;*&lt;/font&gt; thread_function&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;*&lt;/font&gt; dumb&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt; main&lt;font color="#0000ff"&gt;()&lt;br /&gt;{&lt;/font&gt;&lt;br /&gt;    &lt;font color="#800000"&gt;// pthread_t is the thread type defined in POSIX thread&lt;/font&gt;&lt;br /&gt;   pthread_t thread_id&lt;font color="#0000ff"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;    &lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt; res&lt;font color="#0000ff"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;   &lt;font color="#800000"&gt;/** create the new thread&lt;br /&gt;       the new thread ID is stored in thread_id&lt;br /&gt;       the thread's attribute is set to default(NULL)&lt;br /&gt;       it will call the thread_function()&lt;br /&gt;       nothing is passed to the thread_function&lt;br /&gt;   */&lt;/font&gt;&lt;br /&gt;   res &lt;font color="#0000ff"&gt;=&lt;/font&gt; pthread_create&lt;font color="#0000ff"&gt;(&amp;amp;&lt;/font&gt;thread_id&lt;font color="#0000ff"&gt;,&lt;/font&gt; NULL&lt;font color="#0000ff"&gt;, &amp;amp;&lt;/font&gt;thread_function&lt;font color="#0000ff"&gt;,&lt;/font&gt; NULL&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;(&lt;/font&gt;res&lt;font color="#0000ff"&gt;!=&lt;/font&gt;&lt;font color="#008080"&gt;0&lt;/font&gt;&lt;font color="#0000ff"&gt;)&lt;br /&gt;   {&lt;/font&gt;&lt;br /&gt;      perror&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#000080"&gt;&amp;quot;Thread creation failed.&amp;quot;&lt;/font&gt;&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;      exit&lt;font color="#0000ff"&gt;(&lt;/font&gt;EXIT_FAILURE&lt;font color="#0000ff"&gt;);&lt;br /&gt;   }&lt;/font&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/font&gt; &lt;font color="#008080"&gt;0&lt;/font&gt;&lt;font color="#0000ff"&gt;;&lt;br /&gt;}&lt;/font&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;*&lt;/font&gt; thread_function&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;*&lt;/font&gt; dumb&lt;font color="#0000ff"&gt;)&lt;br /&gt;{&lt;/font&gt;&lt;br /&gt;   printf&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#000080"&gt;&amp;quot;the new thread is created.\n&amp;quot;&lt;/font&gt;&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/font&gt; NULL&lt;font color="#0000ff"&gt;;&lt;br /&gt;}&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt; &lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;Notice, since pthread functions are not included in the standard C library, you should add the pthread library yourself&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;&lt;font color="blue"&gt;cc -o simple_thread simple_thread.c -lpthread&lt;/font&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-8759157412203975913?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/8759157412203975913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=8759157412203975913' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8759157412203975913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8759157412203975913'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/03/programming-threads-2-thread-creation.html' title='[Programming] Threads (2) - Thread Creation'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-2982070640059464418</id><published>2008-03-12T22:41:00.008-04:00</published><updated>2008-04-15T22:06:10.698-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiMAX'/><category scheme='http://www.blogger.com/atom/ns#' term='Mobile TV'/><category scheme='http://www.blogger.com/atom/ns#' term='wireless'/><category scheme='http://www.blogger.com/atom/ns#' term='3G'/><title type='text'>[Wireless] New contender in Mobile TV - WiMAX</title><content type='html'>The latest news about WiMAX is that &lt;a href="http://rcrnews.com/apps/pbcs.dll/article?AID=/20080312/FREE/366315307/1014"&gt;NextWave plans to introduce Mobile TV over WiMAX&lt;/a&gt;, which is currently named as &lt;a href="http://www.nextwave.com/page.asp?prmID=616"&gt;MXtv&lt;/a&gt;.  It will support up to 30 frames/second of video, and provides up to 45 mobile TV channels with 300kbps in 10 MHz.  Nextwave will develop this MXtv with its partner Huawei Technologies USA and Alcatel-Lucnet.  The news said they will demonstrate the technology at &lt;a href="http://www.ctiawireless.com/"&gt;CTIA&lt;/a&gt; Wireless 2008 next month in Las Vegas.&lt;br /&gt;&lt;br /&gt;In recent years, IP TV gains a lot of attention.  In the wireline domain, some technologies have been proposed to provide the "Final Mile" data stream transmission for the consumer's premises, such as Passive Optical Network, Ethernet in the First Mile over copper.  In the wireless domain, Mobile TV can be supported by two-way cellular network (such as 3G) or one-way dedicated broadcast network (such as satellite).  Now WiMAX becomes a new platform for Mobile TV.  No matter which one dominates or some of them share the market, the new Multimedia era is running to use.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-2982070640059464418?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/2982070640059464418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=2982070640059464418' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2982070640059464418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2982070640059464418'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/03/wireless-new-contender-in-mobile-tv.html' title='[Wireless] New contender in Mobile TV - WiMAX'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-4590262240037351661</id><published>2008-03-12T01:31:00.005-04:00</published><updated>2008-05-05T23:47:30.139-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='thread'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>[Programming] Threads (1)</title><content type='html'>Another important concept in multi-tasking operating system is &lt;em&gt;threads&lt;/em&gt;. We have learned that a program can &lt;em&gt;&lt;span style="color:#3366ff;"&gt;fork&lt;/span&gt;&lt;/em&gt; a child process to do a different thing. However, at times the overhead of creating a new child process is heavy, especially for some embedded systems which only have limited resources for use. The fact behind this is that a new copy of the original process will be created when forking, such as the memory space and file descriptors. That's what we mentioned before that child process is schedueled independently of the parent process.&lt;br /&gt;&lt;br /&gt;In order to realize multi-tasking with light overhead, some new concepts are introduced to multi-tasking programming, such as light-weight process and threads. Sometimes people just call threads as light-weight processes for the sake of simplicity, although they are not the same thing (for details, you can refer to &lt;a href="http://en.wikipedia.org/wiki/Light-weight_process"&gt;Light-weight process&lt;/a&gt; in wikipedia).&lt;br /&gt;&lt;br /&gt;So in the view of the resource usage, the new created thread does not copy the original system resources used by the creating thread. It shares the same memory space (heap), global variables, file descriptors, signal handlers and other system resources as the original. However, threads have their own stack space.&lt;br /&gt;&lt;br /&gt;If we take a look at the thread in the view of implementation, a thread exists within a process, or more precisely, a thread is a sequence of control within a process. Indeed, a process has at least one thread of execution (also called primary or main thread). This primary thread can create additional threads, and all these threads run the same program in the same process, but they may execute a different part of the program at any time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-4590262240037351661?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/4590262240037351661/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=4590262240037351661' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/4590262240037351661'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/4590262240037351661'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/03/programming-threads-1.html' title='[Programming] Threads (1)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-7682290995180658097</id><published>2008-03-11T12:55:00.009-04:00</published><updated>2008-03-15T01:19:39.448-04:00</updated><title type='text'>[Programming] Processes (3) - Signals</title><content type='html'>A Signal is a special message sent to a process to respond to some conditions.  Some examples of the conditions are: illegal instructions, broken pipe, termination etc.  Those signals are defined in the header file - singal.h.  They are all with prefix SIG.  The following table is a list of some signals. &lt;br /&gt;&lt;br /&gt;&lt;table border="1" cellpadding="1" cellspacing="0" width="400"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Signal Name&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SIGILL&lt;/td&gt;&lt;td&gt;Illegal instruction, indicates the program's stack is corrupted&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SIGINT&lt;/td&gt;&lt;td&gt;Terminal interrupt from keyboard by pressing Ctrl+C&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SIGKILL&lt;/td&gt;&lt;td&gt;Ends a process immediately, which cannot be caught or ignored&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SIGPIPE&lt;/td&gt;&lt;td&gt;Attempts to write on a broken pipe&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SIGQUIT&lt;/td&gt;&lt;td&gt;Quit from keyboard&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;SIGTERM&lt;/td&gt;&lt;td&gt;Requests a process to terminate&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;For a full list of signals, you can find it by typing the command below:&lt;br /&gt;&lt;br /&gt;% man 7 signal&lt;br /&gt;&lt;br /&gt;Generally speaking, signals can be used in the next three situations:&lt;br /&gt;1) send a signal to processes in response to some errors, such as SIGBUS(bus error), SIGSEGV(segmentation violation)&lt;br /&gt;2) send a signal to another process, such as SIGTERM(terminate), SIGKILL(kill the process)&lt;br /&gt;3) send a command to a running program using user-defined signals, such as SIGUSR1&lt;br /&gt;&lt;br /&gt;When a process receives a signal, it will take some actions immediately - either to call another function or ignore it (ignore is also a kind of action).  When it calls another function, the current executing program will be paused and the new function will be executed.  When the function returns, the paused program will resume again.&lt;br /&gt;&lt;br /&gt;You can aslo set or modify the actions to be taken on receipt of signals by using function sigaction().&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-7682290995180658097?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/7682290995180658097/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=7682290995180658097' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/7682290995180658097'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/7682290995180658097'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/03/programming-processes-2-signals.html' title='[Programming] Processes (3) - Signals'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-7381561755943937314</id><published>2008-03-11T02:36:00.001-04:00</published><updated>2008-03-11T02:37:59.844-04:00</updated><title type='text'>[Programming] Processes (2) - Zombie processes</title><content type='html'>Last time we mentioned that we can use fork() to create child processes.  However, you should keep this in mind: the child process is schedulued independently of the parent process.  It implies that you cannot predict which process will execute before or after another, namely, the order of the occurrence of multi processes cannot be forecast.  This situation also occurs in multi-threaded programming. &lt;br /&gt;&lt;br /&gt;Therefore, some advanced, even sophisticated mechanisms must be used in mutlitasking programming to control the programs running in the desired order. &lt;br /&gt;&lt;br /&gt;For example, in some cases you may want the parent process to wait until its child processes have completed.  This can be done using the wait family functions, such as &lt;strong&gt;wait(), waitpid(), wait3()&lt;/strong&gt; etc. &lt;br /&gt;&lt;br /&gt;However, we need to pay attention to the occurrence of "Zombie" processes.  When a child process terminates, its association (such as exit status) with its parent does not vanish immediately, it is still in the system. In this case, this terminated child process becomes a "Zombie" process.  It is the responsibility of the parent process to clean up the zombie child processes.  The wait() function we mentioned above can do this clean up work.  &lt;br /&gt;&lt;br /&gt;If you have too many zombie processes in the system, you may suffer slower performance since they consume resources.  So you need to avoid zombie processes.  Fortunately, when the parent process exits, a special process called &lt;strong&gt;init()&lt;/strong&gt; with process ID of 1 will do the clean up work automatically for you. &lt;br /&gt;&lt;br /&gt;You may ask why we don't notify the parent process when a child terminates.  Great, you make it!  In Linux, child process can send &lt;strong&gt;&lt;em&gt;signals&lt;/em&gt;&lt;/strong&gt; to parent when it terminates.  We'll touch it in the next post.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-7381561755943937314?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/7381561755943937314/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=7381561755943937314' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/7381561755943937314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/7381561755943937314'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/03/programming-processes-2-zombie.html' title='[Programming] Processes (2) - Zombie processes'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-8525079863369374642</id><published>2008-03-09T14:25:00.012-04:00</published><updated>2008-03-09T15:01:01.364-04:00</updated><title type='text'>[Programming] Type casting problem in function's argument</title><content type='html'>Recently someone asked a question of C programming on a discussion board: he has some codes which handle a fixed point array by passing the name of the array to a function, for example:&lt;div style="background:#c0c0c0;border-style:none;border-width:thin;"&gt;&lt;br /&gt;&lt;code&gt;&lt;font color="#000000" size=2&gt;&lt;br /&gt;&lt;font color="#800000"&gt;/** Code 1 */&lt;/font&gt;&lt;br /&gt;&lt;font color="#800000"&gt;// declaration of the function&lt;/font&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/font&gt; f&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;*&lt;/font&gt;pt&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#800000"&gt;// an array of fixed point integer&lt;/font&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt; A&lt;font color="#0000ff"&gt;[&lt;/font&gt;&lt;font color="#008080"&gt;10&lt;/font&gt;&lt;font color="#0000ff"&gt;];&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#800000"&gt;// call the function&lt;/font&gt;&lt;br /&gt;f&lt;font color="#0000ff"&gt;(&lt;/font&gt;A&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The above codes work successfully. Now he tries to extend the code to a floating point array, as follows:&lt;br /&gt;&lt;br /&gt;double B[10];&lt;br /&gt;f((int*)B);&lt;br /&gt;&lt;br /&gt;The compiler didn't complain any error, but the output result is something weird. For example, run the following codes on gcc or visual c, you suppose to get output as 3, but the result is -266631570,&lt;br /&gt;&lt;br /&gt;&lt;div style="background:#c0c0c0;border-style:none;border-width:thin;"&gt;&lt;br /&gt;&lt;pre&gt;&lt;font color="#000000" size=2&gt;&lt;br /&gt;&lt;font color="#800000"&gt;/** Code 2 */&lt;/font&gt;&lt;br /&gt;&lt;font color="#d70000"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/font&gt; test_fun&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;*&lt;/font&gt; px&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt; main&lt;font color="#0000ff"&gt;()&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;{&lt;/font&gt;&lt;br /&gt; &lt;font color="#000080"&gt;&lt;b&gt;double&lt;/b&gt;&lt;/font&gt; a&lt;font color="#0000ff"&gt;[&lt;/font&gt;&lt;font color="#008080"&gt;10&lt;/font&gt;&lt;font color="#0000ff"&gt;];&lt;/font&gt;&lt;br /&gt;&lt;br /&gt; a&lt;font color="#0000ff"&gt;[&lt;/font&gt;&lt;font color="#008080"&gt;0&lt;/font&gt;&lt;font color="#0000ff"&gt;] =&lt;/font&gt; &lt;font color="#008080"&gt;3.14159&lt;/font&gt;&lt;font color="#0000ff"&gt;;&lt;/font&gt;&lt;br /&gt; test_fun&lt;font color="#0000ff"&gt;((&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;*)&lt;/font&gt;a&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt; &lt;font color="#000080"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/font&gt; &lt;font color="#008080"&gt;0&lt;/font&gt;&lt;font color="#0000ff"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;}&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/font&gt; test_fun&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;*&lt;/font&gt;px&lt;font color="#0000ff"&gt;)&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;{&lt;/font&gt;&lt;br /&gt; printf&lt;font color="#0000ff"&gt;(&lt;/font&gt;&lt;font color="#000080"&gt;&amp;quot;%d\n&amp;quot;&lt;/font&gt;&lt;font color="#0000ff"&gt;, *&lt;/font&gt;px&lt;font color="#0000ff"&gt;);&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;}&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt; &lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;We all know that we can type-cast a double variable to an integer variable like this:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;div style="background:#c0c0c0;border-style:none;border-width:thin;"&gt;&lt;br /&gt;&lt;code&gt;&lt;font color="#000000" size=2&gt;&lt;br /&gt;&lt;font color="#800000"&gt;/** Code 3 */&lt;/font&gt;&lt;br /&gt; &lt;font color="#000080"&gt;&lt;b&gt;double&lt;/b&gt;&lt;/font&gt; d&lt;font color="#0000ff"&gt;=&lt;/font&gt;&lt;font color="#008080"&gt;3.14&lt;/font&gt;&lt;font color="#0000ff"&gt;;&lt;/font&gt;&lt;br /&gt; &lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt; c&lt;font color="#0000ff"&gt;;&lt;/font&gt;&lt;br /&gt; c&lt;font color="#0000ff"&gt;=(&lt;/font&gt;&lt;font color="#000080"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;)&lt;/font&gt;d&lt;font color="#0000ff"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;And we can pass an array to a function by the array's name if they are in the same type (as the above code 1). But why cannot we do the similar thing for passing a floating point array's name to a funciton which accepts fixed point variables?&lt;br /&gt;&lt;br /&gt;The answer to this question is: floating point and fixed point numbers are stored in different formats. For floating point number, it conforms with &lt;a href="http://en.wikipedia.org/wiki/IEEE_floating-point_standard"&gt;IEEE754&lt;/a&gt;. For example, for a 32-bit computer, a single-precision binary floating point number is stored in the format of sign(1 bit) + exponent (8 bits) + fraction (23 bits). So if you simply pass the array's name of floating point numbers as function's argument to an array that accommodates fixed point numbers, the function will read the 32-bit floating point number in fixed point format. The compiler doesn't complain because, yes, you can read it. But the result cannot be what you expect.&lt;br /&gt;&lt;br /&gt;The solution to this question may be: 1) cast each element of the floating point array to a fixed point array first, then call the function; 2) re-write the function to support floating point, such as using templates...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-8525079863369374642?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/8525079863369374642/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=8525079863369374642' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8525079863369374642'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8525079863369374642'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/03/programming-type-casting-problem-in.html' title='[Programming] Type casting problem in function&apos;s argument'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-1327040328235862686</id><published>2008-02-29T21:32:00.004-05:00</published><updated>2008-04-15T22:07:18.226-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiMAX'/><category scheme='http://www.blogger.com/atom/ns#' term='LTE'/><category scheme='http://www.blogger.com/atom/ns#' term='4G'/><category scheme='http://www.blogger.com/atom/ns#' term='OFDM'/><category scheme='http://www.blogger.com/atom/ns#' term='MIMO'/><category scheme='http://www.blogger.com/atom/ns#' term='3G'/><title type='text'>[Wireless] Sprint nosedives! Then, WiMAX???</title><content type='html'>Sprint-Nextel lost more than 20 percent of their stocks value after it annnounced fourth-quarter earning (or loss?) yesterday. The shares of its WiMAX partner - Clearwire, also dropped more than 10 percent in two days. &lt;br /&gt;&lt;br /&gt;Now in market, most wireless firms are betting on 3G wireless networks. Even the new handset player, Apple, is going to launch a 3G-capable iPhone this year. Although 3G system was not deployed as fast as it was expected initially, it finally occupies a part of the wireless market and becomes bigger in years. Although WiMAX is newly designed with more advanced technologies, it may have a disadvantage than 3G in time-to-market.&lt;br /&gt;&lt;br /&gt;So, who will drive wireless to the MAX? LTE or WiMAX? I bet nobody can answer this. What we know is: Sprint plans to launch commerical WiMAX service in Q2 2008. Ericsson plans to invest 1.5 billion dollars into next generation wireless systems (LTE or 4G) in three years. &lt;br /&gt;&lt;br /&gt;But I'll say, no matter it's LTE, WiMAX or 4G, the winner is always OFDM+MIMO. :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-1327040328235862686?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/1327040328235862686/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=1327040328235862686' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1327040328235862686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1327040328235862686'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/02/wireless-sprint-nosedives-then-wimax.html' title='[Wireless] Sprint nosedives! Then, WiMAX???'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-1211835494945726420</id><published>2008-02-26T15:27:00.004-05:00</published><updated>2008-04-15T22:07:52.591-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Wi-Fi'/><category scheme='http://www.blogger.com/atom/ns#' term='802.11'/><category scheme='http://www.blogger.com/atom/ns#' term='WEP'/><category scheme='http://www.blogger.com/atom/ns#' term='wireless'/><category scheme='http://www.blogger.com/atom/ns#' term='WPA'/><title type='text'>[Wireless] Free global Wi-Fi network?</title><content type='html'>Today I read an article &lt;a href="http://wireless.itworld.com/4265/wefi-global-wireless-080225/page_1.html"&gt;"Is a free global Wi-Fi network possible?". &lt;/a&gt;It said a company called &lt;a href="http://www.wefi.com"&gt;WeFi&lt;/a&gt; is hoping to provide a virtual global wi-fi network which is free to allow every to log on.&lt;br /&gt;&lt;br /&gt;Actually, WeFi is not the first one working on this. You can find free Wi-Fi hotspots from some websites, such as &lt;a href="http://www.gwifi.net/"&gt;gWifi.net&lt;/a&gt;, &lt;a href="http://www.free-hotspot.com/become_home.htm"&gt;free-hotspot.com&lt;/a&gt; etc. The basic idea of this kind of free wi-fi network is to find unsecured hotspots to access in. However, the distinction of WeFi is that it provides a software that can automatically connect your device to the best available hot spot.So it saves time of switiching among different hotspots if there are some. &lt;br /&gt;&lt;br /&gt;Nevertheless, the ratio of unsecured (free) access spots to all spots in a typical area is not as high as WeFi said to be 50 percent. By checking the hotspots map provieded by WeFi, I found this ratio is about 20 percent on average. We know current 802.11 products all support WEP or WPA and the vendor encourage people to set up a log-in password for data protection. Only some businesses (such as Panera Bread‎) may have open wi-fi spots. For individual wi-fi hotspot owner, unless he is generosity and can bear the low data rate as well as the risk of privacy intrusion, he may make his wi-fi open and free. My two cents: just finding and utilizing the existing open wi-fi resources may not make this virtual free wi-fi network long-lived. As a wi-fi user, I definitely hope the Internet access be free. But, I also know another phrase "There is no such thing as a free lunch."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-1211835494945726420?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/1211835494945726420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=1211835494945726420' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1211835494945726420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1211835494945726420'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/02/wireless-free-global-wi-fi-network.html' title='[Wireless] Free global Wi-Fi network?'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-6370951203707895237</id><published>2008-02-22T20:33:00.014-05:00</published><updated>2008-02-25T20:43:16.596-05:00</updated><title type='text'>[Programming] Processes (1)</title><content type='html'>From today, we will digress to &lt;strong&gt;processes and threads &lt;/strong&gt;programming. &lt;br /&gt;&lt;br /&gt;One standard definition of process (IEEE Std 1003.1) is, "an address space with one or more threads executing within that address space, and the required system resources for those threads". It's like a circular defintion, because in order to understand this definition, you have to know what are threads first. This may not be a problem for those computer gurus, but for beginners, it's better to find a simple explanation, as follows.&lt;br /&gt;&lt;br /&gt;The description of process in &lt;a href="http://en.wikipedia.org/wiki/Process_%28computing%29"&gt;wikipedia&lt;/a&gt; is easy to understand: an instance of a computer program that is being sequentially executed. Further to say, a computer program is just a passive collection of instructions, while a process is the actual execution of those instructions. This is described from the view of the user. On the other hand, in the perspective of operating system, you can say process is the operating system's basic scheduling unit.&lt;br /&gt;&lt;br /&gt;So what elements does a process consist of? It's easy to answer, since process is actaully a program. It contains: &lt;strong&gt;program code, data, variables, current context (execution status), working directory, access rights (mode and ownership), memory and other system resources allocated to the process etc&lt;/strong&gt;. For Linux system, processes may share code and system libraries.&lt;br /&gt;&lt;br /&gt;In Linux/Unix, you can &lt;br /&gt;a) start a new process by the &lt;strong&gt;system() &lt;/strong&gt;function;&lt;br /&gt;b) replace the current process with a new process by the set of &lt;strong&gt;exec() &lt;/strong&gt;funtions (execl, execv, execlp etc.);&lt;br /&gt;c) or duplicate a new process by the &lt;strong&gt;fork() &lt;/strong&gt;function.&lt;br /&gt;&lt;br /&gt;In practice, system() is rarely used to start new processes, because it invokes the new program using a shell, which may cause security problems. So it's preferable to use exec() and fork(). The difference between exec() and fork() is: fork() creates a new child process which is an exact copy of its parent process, but exec() causes a process to cease being an instance of one program and to instead become an instance of another problem.&lt;br /&gt;&lt;br /&gt;The flows of the system(), exec() and fork() call are shown in the following figures.&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_bmgcIB-XFnQ/R8NnbpgVRAI/AAAAAAAAAB0/F0ZEClzbV4g/s1600-h/system.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp0.blogger.com/_bmgcIB-XFnQ/R8NnbpgVRAI/AAAAAAAAAB0/F0ZEClzbV4g/s320/system.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5171090521847055362" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_bmgcIB-XFnQ/R8NmipgVQ_I/AAAAAAAAABs/C7yUoyXcRGw/s1600-h/exec.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp0.blogger.com/_bmgcIB-XFnQ/R8NmipgVQ_I/AAAAAAAAABs/C7yUoyXcRGw/s320/exec.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5171089542594511858" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_bmgcIB-XFnQ/R8Nj75gVQ-I/AAAAAAAAABk/AB8A33PAi5U/s1600-h/fork.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_bmgcIB-XFnQ/R8Nj75gVQ-I/AAAAAAAAABk/AB8A33PAi5U/s320/fork.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5171086677851325410" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-6370951203707895237?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/6370951203707895237/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=6370951203707895237' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6370951203707895237'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6370951203707895237'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/02/programming-processes-1.html' title='[Programming] Processes (1)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_bmgcIB-XFnQ/R8NnbpgVRAI/AAAAAAAAAB0/F0ZEClzbV4g/s72-c/system.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-8249624816378219087</id><published>2008-02-21T13:39:00.007-05:00</published><updated>2008-04-15T22:08:39.704-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='fork()'/><category scheme='http://www.blogger.com/atom/ns#' term='sockets'/><category scheme='http://www.blogger.com/atom/ns#' term='select()'/><category scheme='http://www.blogger.com/atom/ns#' term='poll()'/><title type='text'>[Programming] Sockets programming - multiple clients - prologue</title><content type='html'>Prologue&lt;br /&gt;&lt;br /&gt;Previously we only talked about a very simple case: the server processes one client's request before accepting a connection to the next client. If the processing time for each client is long, and if multiple clients are coming, then the new clients have to wait a long time to be served. Obviously, this is not a good design for the case of multiple concurrent clients. &lt;br /&gt;&lt;br /&gt;Several solutions are used in practice, such as:&lt;br /&gt;1) Multi-process method (forked server processes)&lt;br /&gt;2) Multi-thread method (threaded server processes)&lt;br /&gt;3) Select&lt;br /&gt;4) Poll&lt;br /&gt;&lt;br /&gt;The first multi-process method calls fork() to create a child process. The main server blocks on accept(), waiting for a new connection. Once a new client comes in, the server calls fork(), the new child process will handel the new connection and the main server is able to serve other new incoming requests. &lt;br /&gt;&lt;br /&gt;However, this method suffers the disadvantage that sharing information becomes more complex (you need to use message queues, semaphores etc), and it requires more CPU resource to start and manage a new process for each request.&lt;br /&gt;&lt;br /&gt;The second multi-threaded solution offers the lightweight advantages of the first multi-process method. However, multi-threaded program is not easy to debug. &lt;br /&gt;&lt;br /&gt;The third and fourth approaches, select() or poll(), offer a different method to block execution of the server until a new event occurs. They usually only uese one process to serve multiple client's request. The server will not need shared memory or semaphore for different clients to communicate. For example. select() works by blocing until something happens. &lt;br /&gt;&lt;br /&gt;Oh, hold on, please. You interrupted me, because you already got lost by those new terminologies, such as process, thread, shared memory, semaphore. Yes, in order to understand those, we need to first learn somthing about process/thread. We will cover this in the next several posts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-8249624816378219087?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/8249624816378219087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=8249624816378219087' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8249624816378219087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8249624816378219087'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/02/programming-sockets-programming.html' title='[Programming] Sockets programming - multiple clients - prologue'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-2686184825960160209</id><published>2008-02-19T23:10:00.009-05:00</published><updated>2008-02-20T16:43:09.409-05:00</updated><title type='text'>[Programming] Sockets programming on Linux/Unix</title><content type='html'>Last time we introduced the fundamental of sockets programming and gave an example (WinSock) on the Windows platform. &lt;br /&gt;In deed, socket interface was first introduced in UNIX. In UNIX, socket interface is actually an extension of the concept of a pipe. &lt;br /&gt;However, sockets are created and used differently from pipes because they make a clear distinction between client and server, and they can implement multiple clients attached to a single server.&lt;br /&gt;&lt;br /&gt;Again, let's briefly go over the principles of sockets programming:&lt;br /&gt;1) First, a server application creates a socket using the system call &lt;em&gt;&lt;strong&gt;socket&lt;/strong&gt;&lt;/em&gt;.&lt;br /&gt;2) Next, ther server process gives the socket a name, using the system call &lt;em&gt;&lt;strong&gt;bind&lt;/strong&gt;&lt;/em&gt;. &lt;br /&gt;3) Then the server process waits for a client to connect to the named socket using the system call &lt;em&gt;&lt;strong&gt;listen&lt;/strong&gt;&lt;/em&gt;, which creats a queue for incoming connections.&lt;br /&gt;4) For incoming connections, the server can accept them using the system call &lt;em&gt;&lt;strong&gt;accept&lt;/strong&gt;&lt;/em&gt;.&lt;br /&gt;5) When the server calls accept, a new socket is created that is distinct from the named socket. This new socket is used only for communication with this particular client. The named socket remains for further connections from other clients.&lt;br /&gt;6) Once a connection is established, a two-way communication will be available between the server and the client. They can communicate with each other using sytem call &lt;em&gt;&lt;strong&gt;read/write&lt;/strong&gt;&lt;/em&gt; for AF_UNIX protocol or &lt;em&gt;&lt;strong&gt;send/recv&lt;/strong&gt;&lt;/em&gt; for AF_INET protocol.&lt;br /&gt;7) After communication, a system call close or shutdown is called to release the named socket. &lt;br /&gt;&lt;br /&gt;Client side:&lt;br /&gt;1) The client creates an unamed socket by calling socket.&lt;br /&gt;2) Then the client uses system call &lt;em&gt;&lt;strong&gt;connect&lt;/strong&gt;&lt;/em&gt; to establish with the server by using the server's named socket as an address.&lt;br /&gt;3) If the connection is accepted by the server, then the client can communicate with server using read/write for AF_UNIX protocol or send/recv for AF_INET protocol.&lt;br /&gt;4) Similarly, when communication is finished, a call of close/shutdown is called. &lt;br /&gt;&lt;br /&gt;Here's a very simple example of socket server and client programs.&lt;br /&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;font color="#000000" size=2&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// Local server&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;sys/types.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;sys/socket.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;sys/un.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;unistd.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;int&lt;/b&gt; main()&lt;br /&gt;{&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; server_socketfd, client_socketfd;&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; server_len, client_len;&lt;br /&gt;   &lt;b&gt;struct&lt;/b&gt; sockaddr_un server_address;&lt;br /&gt;   &lt;b&gt;struct&lt;/b&gt; sockaddr_un client_address;&lt;br /&gt;&lt;br /&gt;   unlink(&lt;font color="#0000ff"&gt;&amp;quot;server_socket&amp;quot;&lt;/font&gt;);&lt;br /&gt;   server_socketfd = socket(AF_UNIX, SOCK_STREAM, &lt;font color="#ff0080"&gt;0&lt;/font&gt;);&lt;br /&gt;&lt;br /&gt;   server_address.sun_family = AF_UNIX;&lt;br /&gt;   strcpy(server_address.sun_path, &lt;font color="#0000ff"&gt;&amp;quot;server_socket&amp;quot;&lt;/font&gt;);&lt;br /&gt;   server_len = &lt;b&gt;sizeof&lt;/b&gt;(server_address);&lt;br /&gt;   bind(server_socketfd, (&lt;b&gt;struct&lt;/b&gt; sockaddr *)&amp;amp;server_address, server_len);&lt;br /&gt;&lt;br /&gt;   listen(server_socketfd, &lt;font color="#ff0080"&gt;10&lt;/font&gt;);&lt;br /&gt;   &lt;b&gt;while&lt;/b&gt;(&lt;font color="#ff0080"&gt;1&lt;/font&gt;)&lt;br /&gt;   {&lt;br /&gt;      &lt;b&gt;char&lt;/b&gt; s_sendbuf[] = &lt;font color="#0000ff"&gt;&amp;quot;Welcome to server.&amp;quot;&lt;/font&gt;;&lt;br /&gt;      &lt;b&gt;char&lt;/b&gt; s_recvbuf[&lt;font color="#ff0080"&gt;255&lt;/font&gt;];&lt;br /&gt;      printf(&lt;font color="#0000ff"&gt;&amp;quot;Server waiting\n&amp;quot;&lt;/font&gt;);&lt;br /&gt;&lt;br /&gt;      client_len = &lt;b&gt;sizeof&lt;/b&gt;(client_address);&lt;br /&gt;      client_socketfd = accept(server_socketfd, (&lt;b&gt;struct&lt;/b&gt; sockaddr *)&amp;amp;client_address, &amp;amp;client_len);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;      read(client_socketfd, s_recvbuf, &lt;font color="#ff0080"&gt;255&lt;/font&gt;);&lt;br /&gt;      printf(&lt;font color="#0000ff"&gt;&amp;quot;Message received from client: %s\n&amp;quot;&lt;/font&gt;, s_recvbuf);&lt;br /&gt;      write(client_socketfd, s_sendbuf, strlen(s_sendbuf)+&lt;font color="#ff0080"&gt;1&lt;/font&gt;);&lt;br /&gt;      close(client_socketfd);&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// Local client&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;sys/types.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;sys/socket.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;sys/un.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;unistd.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;int&lt;/b&gt; main()&lt;br /&gt;{&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; socketfd;&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; length, result;&lt;br /&gt;   &lt;b&gt;struct&lt;/b&gt; sockaddr_un address;&lt;br /&gt;   &lt;b&gt;char&lt;/b&gt; sendbuf[] = &lt;font color="#0000ff"&gt;&amp;quot;Hi, this is client 1.&amp;quot;&lt;/font&gt;;&lt;br /&gt;   &lt;b&gt;char&lt;/b&gt; recvbuf[&lt;font color="#ff0080"&gt;255&lt;/font&gt;];&lt;br /&gt;&lt;br /&gt;   socketfd = socket(AF_UNIX, SOCK_STREAM, &lt;font color="#ff0080"&gt;0&lt;/font&gt;);&lt;br /&gt;&lt;br /&gt;   address.sun_family = AF_UNIX;&lt;br /&gt;   strcpy(address.sun_path, &lt;font color="#0000ff"&gt;&amp;quot;server_socket&amp;quot;&lt;/font&gt;);&lt;br /&gt;   length = &lt;b&gt;sizeof&lt;/b&gt;(address);&lt;br /&gt;&lt;br /&gt;   result = connect(socketfd, (&lt;b&gt;struct&lt;/b&gt; sockaddr*)&amp;amp;address, length);&lt;br /&gt;&lt;br /&gt;   &lt;b&gt;if&lt;/b&gt;(result==-&lt;font color="#ff0080"&gt;1&lt;/font&gt;)&lt;br /&gt;   {&lt;br /&gt;      perror(&lt;font color="#0000ff"&gt;&amp;quot;Error:client 1&amp;quot;&lt;/font&gt;);&lt;br /&gt;      exit(&lt;font color="#ff0080"&gt;1&lt;/font&gt;);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   write(socketfd, sendbuf, strlen(sendbuf)+&lt;font color="#ff0080"&gt;1&lt;/font&gt;);&lt;br /&gt;   read(socketfd, recvbuf,&lt;font color="#ff0080"&gt;255&lt;/font&gt;);&lt;br /&gt;   printf(&lt;font color="#0000ff"&gt;&amp;quot;Greeting from server: %s\n&amp;quot;&lt;/font&gt;, recvbuf);&lt;br /&gt;   close(socketfd);&lt;br /&gt;   exit(&lt;font color="#ff0080"&gt;0&lt;/font&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-2686184825960160209?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/2686184825960160209/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=2686184825960160209' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2686184825960160209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2686184825960160209'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/02/programming-sockets-programming-on.html' title='[Programming] Sockets programming on Linux/Unix'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-8194458608637371038</id><published>2008-02-18T11:45:00.009-05:00</published><updated>2008-02-18T12:31:13.854-05:00</updated><title type='text'>[Security] Winpcap installation problem: Error opening file for writing c:\windows\system32\drivers\npf.sys</title><content type='html'>Recently a friend asked me to help him install the winpcap on his computer. &lt;a href="http://www.mirrorservice.org/sites/ftp.wiretapped.net/pub/security/packet-capture/winpcap/"&gt;Winpcap&lt;/a&gt; is the packet capture and network monitoring library for Windows. Some network analyzer (such as &lt;a href="http://www.wireshark.org/"&gt;Wireshark&lt;/a&gt;, the new version of Ethereal) or url sniffer (such as &lt;a href="http://www.urlhelper.com/"&gt;Url helper&lt;/a&gt;) need winpcap. &lt;br /&gt;&lt;br /&gt;However, my friend got an error when installing the winpcap. He tried both the old 3.x version and the new 4.x version of winpcap, but everytime he got an error message "&lt;strong&gt;error opening for writing, c:\windows\system32\drivers\npf.sys&lt;/strong&gt;". We googled the internet and found many people suffered the same problem and no solution was provided so far. Some people said it's due to the insufficient priveledge of the user account to install a driver file, but my friend's account is the administrator. Some other people said you may need to first delete the old npf.sys in the system32\driver folder and then reinstall it again, but we checked this folder and didn't find a file called npf.sys existing. We also closed the firewall and anti-virus software, but the problem is still there. &lt;br /&gt;&lt;br /&gt;Finally, we made another try by copying a virus-free npf.sys from another computer to my friend's computer. Then, we found the reason. The system prompts that we cannot copy npf.sys (34,064 bytes) to npf.sys (0 bytes). But we just mentioned that we already did the check, and we didn't have a file named as npf.sys installed. So the only reason will be: there's a sub-directory called npf.sys existing. We checked again, and Bingo, we got it! &lt;strong&gt;There's a directory called c:\windows\system32\drivers\NPF.SYS existing on the computer (notice, it's not a file, but a directory).&lt;/strong&gt; This NPF.SYS directory is empty and with name in upper case. I suspect there's some other softwares (with high probability to be a trojan or spyware) installed this NPF.SYS directory into the system32\drivers folder (they pretended to be a file of winpcap, then they could capture or sniff your password over the network). Later, it may be removed by anti-virus programs. But, it's not cleaned up, the resudual NPF.SYS directory is still on your system.&lt;br /&gt;&lt;br /&gt;In summary, if you encounterred the same question (Error opening file for writing c:\windows\system32\drivers\npf.sys), try to first check if you have a NPF.SYS directory installed under \windows\system32\drivers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-8194458608637371038?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/8194458608637371038/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=8194458608637371038' title='25 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8194458608637371038'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8194458608637371038'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/02/security-winpcap-installation-problem.html' title='[Security] Winpcap installation problem: Error opening file for writing c:\windows\system32\drivers\npf.sys'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>25</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-9083977033629116761</id><published>2008-01-25T20:38:00.001-05:00</published><updated>2008-04-17T16:05:28.630-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sockets'/><title type='text'>[Programming] Quick guide for network programming (2)</title><content type='html'>&lt;font color="#0000ff"&gt;&lt;strong&gt;Source code for Server's socket:&lt;/strong&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;font color="#000000" size=2&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;winsock2.h&amp;gt; &lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;void&lt;/b&gt; main()&lt;br /&gt;{&lt;br /&gt;   WORD wVersionRequested;&lt;br /&gt;   WSADATA wsaData;&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; err;&lt;br /&gt;&lt;br /&gt;   wVersionRequested = MAKEWORD( &lt;font color="#ff0080"&gt;1&lt;/font&gt;, &lt;font color="#ff0080"&gt;1&lt;/font&gt; );&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// call WSAStartup, initialize winsock.dll and negotiate the socket version&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   err = WSAStartup( wVersionRequested, &amp;amp;wsaData );&lt;br /&gt;   &lt;b&gt;if&lt;/b&gt; ( err != &lt;font color="#ff0080"&gt;0&lt;/font&gt; ) {&lt;br /&gt;      &lt;font color="#000080"&gt;&lt;i&gt;// Tell the user that we could not find a usable WinSock DLL.                                  &lt;/i&gt;&lt;/font&gt;&lt;br /&gt;      &lt;b&gt;return&lt;/b&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;b&gt;if&lt;/b&gt; ( LOBYTE( wsaData.wVersion ) != &lt;font color="#ff0080"&gt;1&lt;/font&gt; ||&lt;br /&gt;        HIBYTE( wsaData.wVersion ) != &lt;font color="#ff0080"&gt;1&lt;/font&gt; ) {&lt;br /&gt;      &lt;font color="#000080"&gt;&lt;i&gt;// Tell the user that we could not find a usable WinSock DLL.                                  &lt;/i&gt;&lt;/font&gt;&lt;br /&gt;      WSACleanup( );&lt;br /&gt;      &lt;b&gt;return&lt;/b&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// a) create a socket&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   SOCKET sockSrv = socket(AF_INET, SOCK_STREAM, &lt;font color="#ff0080"&gt;0&lt;/font&gt;);&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// b) bind&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   SOCKADDR_IN addrSrv;&lt;br /&gt;   addrSrv.sin_addr.S_un.S_addr = htonl(INADDR_ANY); &lt;font color="#000080"&gt;&lt;i&gt;// INADDR_ANY use any IP address of the host, you can use inet_addr(&amp;quot;127.0.0.1&amp;quot;); to designate a specific IP&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   addrSrv.sin_family = AF_INET;&lt;br /&gt;   addrSrv.sin_port = htons(&lt;font color="#ff0080"&gt;6123&lt;/font&gt;);     &lt;font color="#000080"&gt;&lt;i&gt;// use a port number larger than 1024&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   bind(sockSrv, (SOCKADDR *)&amp;amp;addrSrv, &lt;b&gt;sizeof&lt;/b&gt;(SOCKADDR));&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// c) listen&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   listen(sockSrv, &lt;font color="#ff0080"&gt;5&lt;/font&gt;);&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// d) accept&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   SOCKADDR_IN addrClient;&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; len = &lt;b&gt;sizeof&lt;/b&gt;(SOCKADDR);&lt;br /&gt;   &lt;b&gt;while&lt;/b&gt;(&lt;font color="#ff0080"&gt;1&lt;/font&gt;) &lt;font color="#000080"&gt;&lt;i&gt;// waiting for requests from clients&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   {&lt;br /&gt;      SOCKET sockConn = accept(sockSrv, (SOCKADDR *)&amp;amp;addrClient, &amp;amp;len); &lt;font color="#000080"&gt;&lt;i&gt;// create a new socket for this connection&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// e) send/recv&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;      &lt;b&gt;char&lt;/b&gt; sendBuff[&lt;font color="#ff0080"&gt;100&lt;/font&gt;];&lt;br /&gt;      sprintf(sendBuff, &lt;font color="#0000ff"&gt;&amp;quot;Welcome %s to server&amp;quot;&lt;/font&gt;, inet_ntoa(addrClient.sin_addr));&lt;br /&gt;      send(sockConn, sendBuff, strlen(sendBuff)+&lt;font color="#ff0080"&gt;1&lt;/font&gt;, &lt;font color="#ff0080"&gt;0&lt;/font&gt;);&lt;br /&gt;&lt;br /&gt;      &lt;b&gt;char&lt;/b&gt; recvBuff[&lt;font color="#ff0080"&gt;100&lt;/font&gt;];&lt;br /&gt;      recv(sockConn, recvBuff, &lt;font color="#ff0080"&gt;100&lt;/font&gt;, &lt;font color="#ff0080"&gt;0&lt;/font&gt;);&lt;br /&gt;      printf(&lt;font color="#0000ff"&gt;&amp;quot;%s\n&amp;quot;&lt;/font&gt;, recvBuff);&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// f) close the current socket and wait for another request&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;      closesocket(sockConn);     &lt;font color="#000080"&gt;&lt;i&gt;//release the socket for this connection&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;&lt;strong&gt;Source code for Client's Socket programming:&lt;/strong&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;font color="#000000" size=2&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;winsock2.h&amp;gt; &lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;void&lt;/b&gt; main()&lt;br /&gt;{&lt;br /&gt;   WORD wVersionRequested;&lt;br /&gt;   WSADATA wsaData;&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; err;&lt;br /&gt;&lt;br /&gt;   wVersionRequested = MAKEWORD( &lt;font color="#ff0080"&gt;1&lt;/font&gt;, &lt;font color="#ff0080"&gt;1&lt;/font&gt; );&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// call WSAStartup, initialize winsock.dll and negotiate the socket version&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   err = WSAStartup( wVersionRequested, &amp;amp;wsaData );&lt;br /&gt;   &lt;b&gt;if&lt;/b&gt; ( err != &lt;font color="#ff0080"&gt;0&lt;/font&gt; ) {&lt;br /&gt;      &lt;font color="#000080"&gt;&lt;i&gt;// Tell the user that we could not find a usable WinSock DLL.                                  &lt;/i&gt;&lt;/font&gt;&lt;br /&gt;      &lt;b&gt;return&lt;/b&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;b&gt;if&lt;/b&gt; ( LOBYTE( wsaData.wVersion ) != &lt;font color="#ff0080"&gt;1&lt;/font&gt; ||&lt;br /&gt;        HIBYTE( wsaData.wVersion ) != &lt;font color="#ff0080"&gt;1&lt;/font&gt; ) {&lt;br /&gt;      &lt;font color="#000080"&gt;&lt;i&gt;// Tell the user that we could not find a usable WinSock DLL.                                  &lt;/i&gt;&lt;/font&gt;&lt;br /&gt;      WSACleanup( );&lt;br /&gt;      &lt;b&gt;return&lt;/b&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// a) create a socket&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   SOCKET sockClient = socket(AF_INET, SOCK_STREAM, &lt;font color="#ff0080"&gt;0&lt;/font&gt;);&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// b) connect&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   SOCKADDR_IN addrClient;&lt;br /&gt;   addrClient.sin_addr.S_un.S_addr = inet_addr(&lt;font color="#0000ff"&gt;&amp;quot;127.0.0.1&amp;quot;&lt;/font&gt;); &lt;font color="#000080"&gt;&lt;i&gt;// loopback address&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   addrClient.sin_family = AF_INET;&lt;br /&gt;   addrClient.sin_port = htons(&lt;font color="#ff0080"&gt;6123&lt;/font&gt;);&lt;br /&gt;   connect(sockClient, (SOCKADDR *)&amp;amp;addrClient, &lt;b&gt;sizeof&lt;/b&gt;(SOCKADDR));&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// c) send/recv&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;b&gt;char&lt;/b&gt; recvBuff[&lt;font color="#ff0080"&gt;100&lt;/font&gt;];&lt;br /&gt;   recv(sockClient, recvBuff, &lt;font color="#ff0080"&gt;100&lt;/font&gt;, &lt;font color="#ff0080"&gt;0&lt;/font&gt;);&lt;br /&gt;   printf(&lt;font color="#0000ff"&gt;&amp;quot;%s\n&amp;quot;&lt;/font&gt;, recvBuff);&lt;br /&gt;   send(sockClient, &lt;font color="#0000ff"&gt;&amp;quot;This is from client B&amp;quot;&lt;/font&gt;, strlen(&lt;font color="#0000ff"&gt;&amp;quot;This is from client B&amp;quot;&lt;/font&gt;)+&lt;font color="#ff0080"&gt;1&lt;/font&gt;, &lt;font color="#ff0080"&gt;0&lt;/font&gt;);&lt;br /&gt;&lt;br /&gt;&lt;font color="#000080"&gt;&lt;i&gt;// d) close&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   closesocket(sockClient);&lt;br /&gt;   WSACleanup();&lt;br /&gt;}&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-9083977033629116761?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/9083977033629116761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=9083977033629116761' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/9083977033629116761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/9083977033629116761'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/01/programming-quick-guide-for-network.html' title='[Programming] Quick guide for network programming (2)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-3996870829557369835</id><published>2008-01-25T15:06:00.001-05:00</published><updated>2008-04-17T16:05:40.477-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sockets'/><title type='text'>[Programming] Quick guide for network programming (1)</title><content type='html'>&lt;pre&gt;&lt;font color="#000000" size= 2&gt;&lt;br /&gt; &lt;br /&gt;When we talk about network programming, basically it includes two parts: one is the socket programming, another one is the multi-threaded programming.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;I'll give a step-by-step guidance for network programming in my blog. We'll first talk about socket programming, then go to the multi-threaded programming. I'll use the windows system as a demonstration. A TCP server will be first started up, then a TCP cilent will communicate with the server from the loopback IP address 127.0.0.1 with port number 6123. (I suppose you have already known the fundamental of network protocols, such as TCP/UDP, IP, port number etc.) &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;1) What is socket?&lt;/strong&gt;&lt;br /&gt;Shortly put, a socket is a combination of an IP address and a port number of a two-way communication link between two programs on the network. &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;2) Types of sockets:&lt;/strong&gt;&lt;br /&gt;For old version of socket, it provides two types of sockets:&lt;br /&gt;  "Stream Socket": provide connection-oriented, reliable data transmission service, use TCP protocol&lt;br /&gt;  "Datagram Socket": provide connetionless service, packets may not be received in order, use UDP protocol&lt;br /&gt;&lt;br /&gt;Now some new types of sockets have been added, such as: SOCK_RDM (Reliable message datagram), SOCK_SEQPACKET(pseudo-stream packet based on datagrams)&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;3) Flow of the stream socket communication&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt; On the server side, there are seven steps:&lt;br /&gt;  a) create a socket (socket)&lt;br /&gt;  b) bind the socket with a local IP address and a port (bind)&lt;br /&gt;  c) set socket to 'listen' mode (listen)&lt;br /&gt;  d) wait for client's request, when it arrives, accept the request and return &lt;br /&gt;     a new socket for the connection (accept)&lt;br /&gt;  e) communicate with client using the new returned socket (send/recv)&lt;br /&gt;  f) return, wait for another client's request&lt;br /&gt;  g) close the socket (close)&lt;br /&gt;&lt;br /&gt; On the client side, there are four steps:&lt;br /&gt;  a) create a socket (socket)&lt;br /&gt;  b) send request to the server ((connect))&lt;br /&gt;  c) communicate with server (send/recv)&lt;br /&gt;  d) close the socket (close)&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;4) Step-by-step programming&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt; Follow the steps in 3), we first write the code for a TCP server. We use visual c++. You can find the source codes in the next post. Here is the explanation of the code. It's better to read the code and the following descriptions simultaneously.&lt;br /&gt;&lt;br /&gt;  &lt;1&gt; create a Win32 Console Application, set project name to TCPServer&lt;br /&gt;&lt;br /&gt;  &lt;2&gt; write a main function&lt;br /&gt;&lt;br /&gt;  &lt;3&gt; initialize the win32 socket DLL, call function WSAStartup();&lt;br /&gt;&lt;br /&gt;     int WSAStartup(          &lt;br /&gt;        WORD wVersionRequested,&lt;br /&gt;        LPWSADATA lpWSAData    &lt;br /&gt;     );                       &lt;br /&gt;     WSAStartup has two jobs to do:&lt;br /&gt;        i) initiates use of Ws2_32.dll: if WinSock.dll or lower network subsystem is not initialized correctly or is not found, will return WSASYSNOTREADY. &lt;br /&gt;        ii) negotiate the socket version: &lt;br /&gt;           if requested version &lt; MAX version supported by the WinSock.dll, use min(requested version, MAX version)&lt;br /&gt;           if requested version &lt; MIN version supported by the WinSock.dll, return WSAVERNOTSUPPORTED, then call function WSACleanUP() to release resource that has been allocated for WSAStartup&lt;br /&gt;&lt;br /&gt;        The WSADATA or *LPWSADATA used in WSAStartup is a structure, it's defined as&lt;br /&gt;        typedef struct WSAData&lt;br /&gt;        {&lt;br /&gt;                WORD wVersion; // winsock version&lt;br /&gt;                WORD wHighVersion; // highest version in the current winsock library&lt;br /&gt;                char szDescription[WSADESCRIPTION_LEN+1];// for special use&lt;br /&gt;                char szSystemStatus[WSASYS_STATUS_LEN+1];// for special use&lt;br /&gt;                unsigned short iMaxSockets; // maximum num of sockets that can be&lt;br /&gt;                                            // opened, don't use it&lt;br /&gt;                unsighed short iMaxUdpDg; // maximum length of packet, don't use it&lt;br /&gt;                char FAR * lpVendorInfo; // reserved for vendor, never been used&lt;br /&gt;        } WSADATA, *LPWSADATA;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;4&gt; create a socket&lt;br /&gt;&lt;br /&gt;     SOCKET WSAAPI socket(&lt;br /&gt;        int af, // for tcp-ip, it must be AF_INET or PF_INET&lt;br /&gt;        int type, // for winsock 1.1, only SOCKET_STREAM or SOCKET_DGRAM&lt;br /&gt;        int protocol // protocol to be used, is specific to the address family and &lt;br /&gt;                     // socket type, set to 0 for default&lt;br /&gt;     );&lt;br /&gt;&lt;br /&gt;     If no error occurs, it will return a descriptor referencing the new socket. Otherwise, return INVALID_SOCKET.&lt;br /&gt;&lt;br /&gt;  &lt;5&gt; bind&lt;br /&gt;&lt;br /&gt;     int bind(&lt;br /&gt;        SOCKET s, // descriptor identifying an unbound socket&lt;br /&gt;        const struct sockaddr* name, // the address to assign to the socket, &lt;br /&gt;                                     // it may be varied with different &lt;br /&gt;                                     // address families, so we should use the next &lt;br /&gt;                                     // parameter to indicate the &lt;br /&gt;                                     // length of this address structure&lt;br /&gt;        int namelen // length of the value, in bytes&lt;br /&gt;     );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     The sockaddr is defined as:&lt;br /&gt;     struct sockaddr {&lt;br /&gt;        u_short sa_family;&lt;br /&gt;        char sa_data[14];&lt;br /&gt;     };&lt;br /&gt;&lt;br /&gt;     For different address family, we should use differnt structure to replace this sockaddr. &lt;br /&gt;     For TCP/IP, sockaddr_in is used. &lt;br /&gt;     The definition of sockaddr_in is:&lt;br /&gt;&lt;br /&gt;     struct sockaddr_in {&lt;br /&gt;        short   sin_family; // for IP address, it's AF_INET&lt;br /&gt;        u_short sin_port; // port number&lt;br /&gt;        struct  in_addr sin_addr; // IP address of the host, &lt;br /&gt;                                  // should use "network byte order"&lt;br /&gt;        char    sin_zero[8]; // padding bytes, to make the length equals to the &lt;br /&gt;                             // sockaddr structure&lt;br /&gt;     };&lt;br /&gt;     where the "network byte order" is the same as the well-known big_endian order. &lt;br /&gt;&lt;br /&gt;    It will return 0, if successful; otherwise, return SOCKET_ERROR &lt;br /&gt;&lt;br /&gt;  &lt;6&gt; listen&lt;br /&gt;&lt;br /&gt;     int listen(&lt;br /&gt;        SOCKET s,        // descriptor identifying a socket&lt;br /&gt;        int backlog      // max length of the queue of pending connections&lt;br /&gt;     );&lt;br /&gt;&lt;br /&gt;  &lt;7&gt; accept&lt;br /&gt;&lt;br /&gt;     SOCKET accept(&lt;br /&gt;        SOCKET s, // identifying a socket&lt;br /&gt;        struct sockaddr* addr, // used to store the client's ip addr and port num&lt;br /&gt;        int* addrlen // length of the &lt;br /&gt;     );&lt;br /&gt;&lt;br /&gt;  &lt;8&gt; send/recv&lt;br /&gt;     int send(&lt;br /&gt;        SOCKET s,&lt;br /&gt;        const char* buf,&lt;br /&gt;        int len,&lt;br /&gt;        int flags&lt;br /&gt;     );&lt;br /&gt;&lt;br /&gt;  &lt;9&gt; Include the header file &lt;winsock2.h&gt;, add ws2_32.lib to the project, the operation in Visual C++ is:&lt;br /&gt;        project -&gt; setting -&gt; link -&gt; Object/library modules, append ws2_32.lib to the end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;10&gt; Then let's go to the client side. First add a new project to the current workspace, name it as "TCPClient".&lt;br /&gt;&lt;br /&gt;  &lt;11&gt; Similar as the Server code, first call WSAStartup to initialize the ws2_32.dll and negotiate the socket version, then create a socket&lt;br /&gt;&lt;br /&gt;  &lt;12&gt; connect&lt;br /&gt;       &lt;br /&gt;     int connect(&lt;br /&gt;        SOCKET s,&lt;br /&gt;        const struct sockaddr* name,&lt;br /&gt;        int namelen&lt;br /&gt;     );&lt;br /&gt;&lt;br /&gt;  &lt;13&gt; After connect, call function send/recv, and finnaly call closesocket and WSACleanup as in server side.&lt;br /&gt;&lt;br /&gt;  &lt;14&gt; Include the header file &lt;winsock2.h&gt; and add ws2_32.lib to this project too&lt;br /&gt;&lt;br /&gt;  &lt;15&gt; Compile all files, run TCPServer first, then run TCPClient, we will get the following results, as shown in the figure&lt;br /&gt; &lt;br /&gt;5) Some &lt;strong&gt;functions&lt;/strong&gt; are used in the program for the conversion of the address, they are&lt;br /&gt;   htons():  converts a u_short from host to TCP/IP network byte order &lt;br /&gt;   htonl():  converts a u_long from host to TCP/IP network byte order &lt;br /&gt;   ntohs():  converts a u_short from TCP/IP network byte order to host byte order&lt;br /&gt;   ntohl():  converts a u_long from TCP/IP network byte order to host byte order&lt;br /&gt;   inet_ntoa(): converts an (Ipv4) Internet network address into a string in Internet standard dotted-decimal format&lt;br /&gt;   inet_addr(): converts a string containing an (Ipv4) Internet Protocol dotted address into a proper address for the IN_ADDR structure&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_bmgcIB-XFnQ/R5pMsuigZGI/AAAAAAAAABQ/pjj4zHW2Rxw/s1600-h/TCP_SOCKET.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp2.blogger.com/_bmgcIB-XFnQ/R5pMsuigZGI/AAAAAAAAABQ/pjj4zHW2Rxw/s320/TCP_SOCKET.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5159520654397039714" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-3996870829557369835?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/3996870829557369835/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=3996870829557369835' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3996870829557369835'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3996870829557369835'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/01/programming-quick-guide-of-network.html' title='[Programming] Quick guide for network programming (1)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_bmgcIB-XFnQ/R5pMsuigZGI/AAAAAAAAABQ/pjj4zHW2Rxw/s72-c/TCP_SOCKET.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-4777605618264621782</id><published>2008-01-24T15:10:00.001-05:00</published><updated>2008-04-15T22:09:40.127-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='in-place'/><title type='text'>[Algorithm] Reverse words in a string</title><content type='html'>This is an interview problem. Given a string, such as "tell me something", output the string as "something me tell", i.e. reverse every word in the string. Here is a demo program in C code, it's easy to understand with the comments given in the code. The basic idea is, scan the string from the end, find the beginning and the end of each word, then write to a temporary buffer.&lt;br /&gt;&lt;br /&gt;&lt;a name="top"&gt;&lt;/a&gt;&lt;br /&gt;&lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;font color="#000000" size=2&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;iostream.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#008000"&gt;#include &amp;lt;string.h&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;void&lt;/b&gt; ReserveWordsInString(&lt;b&gt;char&lt;/b&gt; string1[])&lt;br /&gt;{&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// get the length of the input string&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; length=&lt;font color="#ff0080"&gt;0&lt;/font&gt;;&lt;br /&gt;   &lt;b&gt;while&lt;/b&gt; (string1[length]!=&lt;font color="#ff8000"&gt;'\0'&lt;/font&gt;)&lt;br /&gt;      length++;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// allocate memory space for a temporary buffer, used to store the temporary result&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;b&gt;char&lt;/b&gt; *buffer= (&lt;b&gt;char&lt;/b&gt; *)malloc(length+&lt;font color="#ff0080"&gt;1&lt;/font&gt;);&lt;br /&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// declare four indicators&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// MoveInd: from length to 0, used to traverse the input string&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// EndInd: indicate the end of a word that is to be reversed in the input string&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// BeginInd: indicate the begin of the word that is to be reversed in the input string&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// WriteInd: the indicator of the writing position in the temporary buffer&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; MoveInd, BeginInd, EndInd, WriteInd;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// initialize the MoveInd to the end of the input string, WriteInd to the begin of the temporary buffer&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   MoveInd = length-&lt;font color="#ff0080"&gt;1&lt;/font&gt;;&lt;br /&gt;   WriteInd = &lt;font color="#ff0080"&gt;0&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt;   &lt;b&gt;while&lt;/b&gt; (MoveInd&amp;gt;=&lt;font color="#ff0080"&gt;0&lt;/font&gt;)&lt;br /&gt;   {&lt;br /&gt;      &lt;b&gt;if&lt;/b&gt; (string1[MoveInd]!=&lt;font color="#ff8000"&gt;' '&lt;/font&gt;)  &lt;font color="#000080"&gt;&lt;i&gt;// if it's a word charactor&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;      {&lt;br /&gt;         EndInd=MoveInd;&lt;br /&gt;         &lt;font color="#000080"&gt;&lt;i&gt;// scan the current word, find the next non-word charactor&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;         &lt;b&gt;while&lt;/b&gt;(MoveInd&amp;gt;=&lt;font color="#ff0080"&gt;0&lt;/font&gt; &amp;amp;&amp;amp; string1[MoveInd]!=&lt;font color="#ff8000"&gt;' '&lt;/font&gt;)&lt;br /&gt;         {&lt;br /&gt;            MoveInd--;&lt;br /&gt;         }&lt;br /&gt;         &lt;font color="#000080"&gt;&lt;i&gt;// copy the word to the temporary buffer&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;         &lt;b&gt;for&lt;/b&gt; (BeginInd=MoveInd+&lt;font color="#ff0080"&gt;1&lt;/font&gt;; BeginInd &amp;lt;= EndInd; BeginInd++, WriteInd++)&lt;br /&gt;         {&lt;br /&gt;            buffer[WriteInd]=string1[BeginInd];&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;      &lt;b&gt;else&lt;/b&gt;&lt;br /&gt;      {&lt;br /&gt;         &lt;font color="#000080"&gt;&lt;i&gt;// write the non-word charactor directly to the temporary buffer&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;         buffer[WriteInd++]=string1[MoveInd--];&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// it is better to append \0 to the end of the buffer&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   buffer[length]=&lt;font color="#ff8000"&gt;'\0'&lt;/font&gt;;&lt;br /&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// copy the buffer to the input string for output&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;b&gt;for&lt;/b&gt; (&lt;b&gt;int&lt;/b&gt; i=&lt;font color="#ff0080"&gt;0&lt;/font&gt;; i&amp;lt;length; i++)&lt;br /&gt;      string1[i]=buffer[i];&lt;br /&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// free the allocated memory for the buffer&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   free(buffer);&lt;br /&gt;}&lt;br /&gt;&lt;b&gt;void&lt;/b&gt; main()&lt;br /&gt;{&lt;br /&gt;   &lt;b&gt;char&lt;/b&gt; string1[]=&lt;font color="#0000ff"&gt;&amp;quot;This is a C program, for word reverse.&amp;quot;&lt;/font&gt;;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// this is a tricky method in getting the size of an array, explanation is below the code&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;b&gt;int&lt;/b&gt; length = &lt;b&gt;sizeof&lt;/b&gt;(string1)/&lt;b&gt;sizeof&lt;/b&gt;(string1[&lt;font color="#ff0080"&gt;0&lt;/font&gt;]);&lt;br /&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// Call the function&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   ReserveWordsInString(string1);&lt;br /&gt;&lt;br /&gt;   &lt;font color="#000080"&gt;&lt;i&gt;// output the result&lt;/i&gt;&lt;/font&gt;&lt;br /&gt;   &lt;b&gt;for&lt;/b&gt; (&lt;b&gt;int&lt;/b&gt; i=&lt;font color="#ff0080"&gt;0&lt;/font&gt;; i&amp;lt;length; i++)&lt;br /&gt;   {&lt;br /&gt;      cout&amp;lt;&amp;lt;string1[i];&lt;br /&gt;   }&lt;br /&gt;   cout&amp;lt;&amp;lt;endl;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;Notes: In this program, we encountered a problem, how to get the length of an array or a string? &lt;br /&gt;&lt;br /&gt;A well-known and tricky method is to use &lt;strong&gt;"sizeof(array)/sizeof(array[0]);", &lt;/strong&gt;this works in the main program. However, if the array is the input argument of a function, this one doesn't work. Because in this case, the type of the array identifier "decays" into a pointer to the base type, and its value is set to the address of the first element in the array. &lt;br /&gt;So, my opinion is, always traversing the array from the beginning to the end to get the length, like "for(int i=0; array[i]!='\0'; i++)".&lt;br /&gt;&lt;br /&gt;A more decent algorithm is: first reverse the whole string in characters, e.g. reverse "tell me something" to "gnihtemos em llet", then using the similar method as above to locate the beginning and end of each word, then reverse each word in characters, e.g. reverse "gnihtemos" to "something". This is an in-place method, which avoids using the extra temporaray buffer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-4777605618264621782?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/4777605618264621782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=4777605618264621782' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/4777605618264621782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/4777605618264621782'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2008/01/programming-reverse-words-in-string.html' title='[Algorithm] Reverse words in a string'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-6736773744195479152</id><published>2007-12-31T12:17:00.001-05:00</published><updated>2008-04-15T22:11:43.519-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Home Agent'/><category scheme='http://www.blogger.com/atom/ns#' term='Mobile IP'/><category scheme='http://www.blogger.com/atom/ns#' term='Foreign Agent'/><category scheme='http://www.blogger.com/atom/ns#' term='wireless'/><category scheme='http://www.blogger.com/atom/ns#' term='Care-Of Address'/><title type='text'>Mobile IP - Quick learn</title><content type='html'>&lt;pre&gt;&lt;br /&gt;A very short description of Mobile IP is given in this post:&lt;br /&gt;    &lt;br /&gt;Purpose of Mobile IP: &lt;br /&gt;    Keep the mobile node's IP address unchanged when mobile node moves&lt;br /&gt;    &lt;br /&gt;Main modules used in Mobile IP: &lt;br /&gt;    MN(Mobile Node) - has a permanent home address &lt;br /&gt;    CN(Correspondent Node) - a host in the traditional network &lt;br /&gt;    HA(Home Agent) &lt;br /&gt;    FA(Foreign Agent) &lt;br /&gt;    COA(Care-Of Address) - the 2nd IP address of the MN &lt;br /&gt;    &lt;br /&gt;How Mobile IP works: &lt;br /&gt;    1) MN first finds the FA's info (because FA broadcasts its information     &lt;br /&gt;       periodically) - Agent Discovery &lt;br /&gt;    2) If MN is still in its HA's area, nothing to do with Mobile IP; else MN needs     &lt;br /&gt;       to get a COA &lt;br /&gt;    3) MN registers the COA to its HA through FA (HA maintains a table,     &lt;br /&gt;       including MN's COA) - Registration &lt;br /&gt;    4) HA sends data to FA through a tunnel - Tunneling &lt;br /&gt;    5) FA sends data to CN (MS's data is sent to CN through FA, not going back     &lt;br /&gt;       to HA) &lt;br /&gt;    &lt;br /&gt;Further explanation: &lt;br /&gt;    &lt;br /&gt;Agent Discovery&lt;br /&gt;    Extend the ICMP (Internet Control Message Protocol) message&lt;br /&gt;    IRDP (ICMP Router Discovery Protocol) - automatically find the local router&lt;br /&gt;     1) HA/FA use ICMP/IRDP to broadcast their info - agent broadcast&lt;br /&gt;     2) MN sends the agent request (also in broadcasting)&lt;br /&gt; How to determine the mobility? ("life time" in IRDP)&lt;br /&gt;     1) Agent sends IRDP including a "life time" field&lt;br /&gt;     2) MN compares the network prefix in the broadcast messages to check if it's&lt;br /&gt;        moved&lt;br /&gt;     3) if MN cannot receive any broadcast message&lt;br /&gt;        i) try to contact HA, as if it's back to HA&lt;br /&gt;        ii) try to use DHCP or manual configuration&lt;br /&gt;Registration&lt;br /&gt;    MN -&gt; FA -&gt; HA (bind the 1st IP and the 2nd IP addresses together)&lt;br /&gt;    When MN returns HA, needs to cancel the registration&lt;br /&gt;&lt;br /&gt;    MN's Co-located COA: MN sends registration request to HA directly, tunneling is  &lt;br /&gt;        from HA to MN, COA is MN's address&lt;br /&gt;    In this case, there's no FA and HA in the traditional network &lt;br /&gt;        (using DHCP/manual configuration to get 2nd IP)&lt;br /&gt;    PROS: no FA needed; &lt;br /&gt;    CONS: MN needs two IP addr, two overlapped IP protocol stacks&lt;br /&gt;&lt;br /&gt;    FA's COA: FA sends the registration request to HA for MN, tunneling is from HA &lt;br /&gt;        to FA, COA is the FA's address&lt;br /&gt;       PROS: multiple MN can share one COA, so IP address is saved; &lt;br /&gt;       CONS: need FA&lt;br /&gt;    &lt;br /&gt;    Frequent registration: on the boundary of two networks&lt;br /&gt;        1) Data link layer solution: &lt;br /&gt;           Use layer-2 capability to manage the mobility, to reduce layer-3 mobility&lt;br /&gt;        2) Mobile IP multiple binding:&lt;br /&gt;           Similar as soft hand-over in CDMA&lt;br /&gt;           In HA, for one registered MN, binds multiple COAs for this MN (when MN is &lt;br /&gt;           on the boundary of multiple FAs)&lt;br /&gt;    &lt;br /&gt;Tunneling (data forwarding): assure transparent transmission&lt;br /&gt;    1) CN's information is still forwarded to HA (for CN, any MN is treated as if it &lt;br /&gt;       is fixed)&lt;br /&gt;    2) HA uses proxy ARP to capture this information &lt;br /&gt;       HA works as an agent of the MN to give the MAC back to the CN&lt;br /&gt;    3) Use tunnel to forward data to FA (FA records MN's MAC addr when MN is &lt;br /&gt;       registering)&lt;br /&gt;    4) Reverse data is delivered to CN directly&lt;br /&gt;    &lt;br /&gt;Functions of HA and FA:&lt;br /&gt;HA: &lt;br /&gt;    1) Act as a router &lt;br /&gt;    2) Manage the MN's host routing (binding table, maintain different tunnel to &lt;br /&gt;       different COA) &lt;br /&gt;    3) Manage and operate tunnel's interface (encapsulate beared protocol and then &lt;br /&gt;       forward with bearing method)&lt;br /&gt;&lt;br /&gt;FA:&lt;br /&gt;    1) Manage and operate tunnel's interface&lt;br /&gt;    2) Manage visited MN's list (in registration)&lt;br /&gt;    3) Use ARP to access MN (FA gets the original IP packet, but FA cannot access MN &lt;br /&gt;       directly since FA and MN are not in the same network, so FA needs to use ARP)&lt;br /&gt;    &lt;br /&gt;Encapsulation process in Mobile IP:&lt;br /&gt;    1) IP in IP encapsulation - an outer IP header is inserted to the front&lt;br /&gt;    2) Minimum encapsulation - reduce redundant information of the inner IP datagram&lt;br /&gt;    3) GRE (Generic Routing Encapsulation) - encapsulate a wide variety of network &lt;br /&gt;       layer packets inside IP tunneling packets&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-6736773744195479152?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/6736773744195479152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=6736773744195479152' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6736773744195479152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6736773744195479152'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/12/mobile-ip-quick-learn.html' title='Mobile IP - Quick learn'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-8563167596192730250</id><published>2007-09-10T22:32:00.001-04:00</published><updated>2008-02-26T22:44:51.978-05:00</updated><title type='text'>[Code] Non-recursive pre-order traversal of a tree</title><content type='html'>Traversal of a tree data structure often uses recursive algorithm. Without recursion, how to solve the problem? Here is the demo code I programmed in C. &lt;br /&gt;&lt;style type="text/css"&gt;&lt;br /&gt;    &lt;!--code { font-family: Courier New, Courier; font-size: 8pt; margin: 0px; }--&gt;&lt;br /&gt;  &lt;/style&gt;&lt;br /&gt;&lt;table border="0" cellpadding="0" cellspacing="0" bgcolor="cccccc"&gt;&lt;br /&gt;   &lt;tr&gt;&lt;br /&gt;  &lt;!-- start source code --&gt;&lt;br /&gt;   &lt;td nowrap="nowrap" valign="top" align="left"&gt;&lt;br /&gt;    &lt;code&gt;&lt;br /&gt;&lt;font color="#808080"&gt;001&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;#include&amp;nbsp;&amp;lt;iostream&amp;gt;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;002&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;using&amp;nbsp;namespace&amp;nbsp;std;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;003&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;/**&amp;nbsp;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;004&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;Definition&amp;nbsp;of&amp;nbsp;NODE&amp;nbsp;of&amp;nbsp;the&amp;nbsp;TREE&amp;nbsp;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;005&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;006&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;typedef&amp;nbsp;struct&amp;nbsp;NodeT&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;007&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;008&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;struct&amp;nbsp;NodeT&amp;nbsp;*left;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;009&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;struct&amp;nbsp;NodeT&amp;nbsp;*right;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;010&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;char&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;data;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;011&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#000000"&gt;NODE;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;012&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;013&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;Definition&amp;nbsp;of&amp;nbsp;Element&amp;nbsp;of&amp;nbsp;the&amp;nbsp;STACK&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;014&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;015&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;typedef&amp;nbsp;struct&amp;nbsp;ElementS&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;016&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;017&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;struct&amp;nbsp;ElementS&amp;nbsp;*next;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;018&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;NODE&amp;nbsp;*data;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;019&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;020&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;/**&amp;nbsp;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;021&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;recursive&amp;nbsp;version&amp;nbsp;of&amp;nbsp;Pre-order&amp;nbsp;traversal&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;022&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;void&amp;nbsp;PreOrder(NODE&amp;nbsp;*&amp;nbsp;root)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;023&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;Algorithm:&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;024&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;Print&amp;nbsp;out&amp;nbsp;the&amp;nbsp;ROOT's&amp;nbsp;value&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;025&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;Do&amp;nbsp;a&amp;nbsp;pre-order&amp;nbsp;traversal&amp;nbsp;on&amp;nbsp;the&amp;nbsp;LEFT&amp;nbsp;sub-tree&amp;nbsp;of&amp;nbsp;the&amp;nbsp;ROOT&amp;nbsp;node&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;026&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;Do&amp;nbsp;a&amp;nbsp;pre-order&amp;nbsp;traversal&amp;nbsp;on&amp;nbsp;the&amp;nbsp;RIGHT&amp;nbsp;sub-tree&amp;nbsp;of&amp;nbsp;the&amp;nbsp;ROOT&amp;nbsp;node&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;027&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;028&lt;/font&gt;&amp;nbsp;&lt;font color="#7f0055"&gt;&lt;b&gt;void&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;PreOrder&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;NODE&amp;nbsp;*&amp;nbsp;root&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;029&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;030&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;if&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;root&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;031&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;032&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;root-&amp;gt;data&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;-&amp;gt;&amp;#34;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;033&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;PreOrder&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;root-&amp;gt;left&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;034&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;PreOrder&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;root-&amp;gt;right&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;035&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;036&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;037&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;038&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;039&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;/**&amp;nbsp;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;040&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;non-recursive&amp;nbsp;version&amp;nbsp;of&amp;nbsp;Pre-order&amp;nbsp;traversal&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;041&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;void&amp;nbsp;PreOrderNonRecur(NODE&amp;nbsp;*root)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;042&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;Algorithm:&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;043&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;create&amp;nbsp;a&amp;nbsp;stack&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;044&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;PUSH&amp;nbsp;the&amp;nbsp;root&amp;nbsp;node&amp;nbsp;of&amp;nbsp;the&amp;nbsp;tree&amp;nbsp;into&amp;nbsp;the&amp;nbsp;stack&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;045&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;While&amp;nbsp;the&amp;nbsp;stack&amp;nbsp;is&amp;nbsp;not&amp;nbsp;empty&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;046&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;POP&amp;nbsp;a&amp;nbsp;node&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;047&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;If&amp;nbsp;the&amp;nbsp;node&amp;nbsp;is&amp;nbsp;not&amp;nbsp;NULL&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;048&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;Print&amp;nbsp;the&amp;nbsp;value&amp;nbsp;of&amp;nbsp;the&amp;nbsp;node&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;049&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;PUSH&amp;nbsp;the&amp;nbsp;node's&amp;nbsp;right&amp;nbsp;child&amp;nbsp;into&amp;nbsp;the&amp;nbsp;stack&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;050&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;PUSH&amp;nbsp;the&amp;nbsp;node's&amp;nbsp;left&amp;nbsp;child&amp;nbsp;into&amp;nbsp;the&amp;nbsp;stack&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;051&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;052&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;bool&amp;nbsp;CreateStack&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT&amp;nbsp;**stack&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;053&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;054&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;*stack=NULL;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;055&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return&amp;nbsp;true&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;056&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;057&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;bool&amp;nbsp;DeleteStack&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT&amp;nbsp;**stack&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;058&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;059&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT&amp;nbsp;*next;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;060&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;while&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;*stack&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;061&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;062&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;next=&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;*stack&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;-&amp;gt;next;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;063&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;delete&amp;nbsp;*stack;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;064&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;*stack=next;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;065&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;066&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return&amp;nbsp;true&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;067&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;068&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;bool&amp;nbsp;Push&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT&amp;nbsp;**stack,&amp;nbsp;NODE&amp;nbsp;*data&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;069&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;070&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT&amp;nbsp;*p&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;071&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;!p&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return&amp;nbsp;false&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;072&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;p-&amp;gt;data&amp;nbsp;=&amp;nbsp;data;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;073&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;p-&amp;gt;next&amp;nbsp;=&amp;nbsp;*stack;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;074&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;*stack=p;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;075&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return&amp;nbsp;true&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;076&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;077&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;bool&amp;nbsp;Pop&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT&amp;nbsp;**stack,&amp;nbsp;NODE&amp;nbsp;**data&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;078&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;079&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT&amp;nbsp;*p;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;080&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;p=*stack;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;081&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;!p&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return&amp;nbsp;false&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;082&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;*data&amp;nbsp;=&amp;nbsp;p-&amp;gt;data;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;083&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;*stack=&amp;nbsp;p-&amp;gt;next;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;084&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;delete&amp;nbsp;p;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;085&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;return&amp;nbsp;true&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;086&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;087&lt;/font&gt;&amp;nbsp;&lt;font color="#7f0055"&gt;&lt;b&gt;void&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;PreOrderNonRecur&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;NODE&amp;nbsp;*root&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;088&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;089&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;ELEMENT&amp;nbsp;*theStack;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;090&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;NODE&amp;nbsp;*data;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;091&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;NODE&amp;nbsp;*curNode;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;092&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;093&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;CreateStack&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;&amp;amp;theStack&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;094&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;Push&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;&amp;amp;theStack,&amp;nbsp;root&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;095&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;096&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;while&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;Pop&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;&amp;amp;theStack,&amp;nbsp;&amp;amp;data&lt;/font&gt;&lt;font color="#000000"&gt;))&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;097&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;098&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;curNode&amp;nbsp;=&amp;nbsp;data;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;099&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;curNode&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;100&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;101&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;cout&amp;lt;&amp;lt;curNode-&amp;gt;data&amp;lt;&amp;lt;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;-&amp;gt;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;102&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;Push&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;&amp;amp;theStack,&amp;nbsp;curNode-&amp;gt;right&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;103&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;Push&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;&amp;amp;theStack,&amp;nbsp;curNode-&amp;gt;left&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;104&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;105&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;106&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;DeleteStack&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;&amp;amp;theStack&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;107&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;108&lt;/font&gt;&amp;nbsp;&lt;font color="#7f0055"&gt;&lt;b&gt;void&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;main&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;109&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;{&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;110&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;NODE&amp;nbsp;a,b,c,d,e,f,g;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;111&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;/**&amp;nbsp;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;112&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;manually&amp;nbsp;construct&amp;nbsp;the&amp;nbsp;tree&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;113&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;114&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;a.left=&amp;amp;b;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;115&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;a.right=&amp;amp;c;&amp;nbsp;&amp;nbsp;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;116&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;b.left=NULL;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;117&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;b.right=&amp;amp;d;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;118&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;c.left=&amp;amp;e;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;119&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;c.right=&amp;amp;f;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;120&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;d.left=&amp;amp;g;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;121&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;d.right=NULL;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;122&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;e.left=NULL;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;123&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;e.right=NULL;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;124&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;f.left=NULL;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;125&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;f.right=NULL;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;126&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;g.left=NULL;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;127&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;g.right=NULL;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;128&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;a.data=&lt;/font&gt;&lt;font color="#990000"&gt;'a'&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;129&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;b.data=&lt;/font&gt;&lt;font color="#990000"&gt;'b'&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;130&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;c.data=&lt;/font&gt;&lt;font color="#990000"&gt;'c'&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;131&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;d.data=&lt;/font&gt;&lt;font color="#990000"&gt;'d'&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;132&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;e.data=&lt;/font&gt;&lt;font color="#990000"&gt;'e'&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;133&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;f.data=&lt;/font&gt;&lt;font color="#990000"&gt;'f'&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;134&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;g.data=&lt;/font&gt;&lt;font color="#990000"&gt;'g'&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;135&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;136&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;cout&amp;lt;&amp;lt;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;Recursive&amp;nbsp;pre-order&amp;nbsp;traversal&amp;nbsp;of&amp;nbsp;the&amp;nbsp;tree:&amp;nbsp;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;&amp;lt;&amp;lt;endl;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;137&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;PreOrder&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;&amp;amp;a&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;138&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;cout&amp;lt;&amp;lt;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;End&amp;nbsp;of&amp;nbsp;traversal&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;139&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;cout&amp;lt;&amp;lt;endl;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;140&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;141&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;cout&amp;lt;&amp;lt;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;Non-recursive&amp;nbsp;pre-order&amp;nbsp;traversal&amp;nbsp;of&amp;nbsp;the&amp;nbsp;tree:&amp;nbsp;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;&amp;lt;&amp;lt;endl;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;142&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;PreOrderNonRecur&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;&amp;amp;a&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;143&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;cout&amp;lt;&amp;lt;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;End&amp;nbsp;of&amp;nbsp;traversal&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;144&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;145&lt;/font&gt;&amp;nbsp;&lt;font color="#000000"&gt;}&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;146&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;/**&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;147&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;the&amp;nbsp;output&amp;nbsp;should&amp;nbsp;be&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;148&lt;/font&gt;&amp;nbsp;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#3f5fbf"&gt;a-&amp;gt;b-&amp;gt;d-&amp;gt;g-&amp;gt;c-&amp;gt;e-&amp;gt;f-&amp;gt;END&lt;/font&gt; &lt;br /&gt;&lt;font color="#808080"&gt;149&lt;/font&gt;&amp;nbsp;&lt;font color="#3f5fbf"&gt;*/&lt;/font&gt;&lt;/code&gt;    &lt;br /&gt;   &lt;/td&gt;&lt;br /&gt;  &lt;!-- end source code --&gt;&lt;br /&gt;   &lt;/tr&gt;   &lt;br /&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-8563167596192730250?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/8563167596192730250/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=8563167596192730250' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8563167596192730250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/8563167596192730250'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/09/non-recursive-pre-order-traversal-of.html' title='[Code] Non-recursive pre-order traversal of a tree'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-6754288472170166835</id><published>2007-09-01T11:33:00.001-04:00</published><updated>2008-04-15T22:12:10.248-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiMAX'/><category scheme='http://www.blogger.com/atom/ns#' term='OFDMA'/><category scheme='http://www.blogger.com/atom/ns#' term='OFDM'/><category scheme='http://www.blogger.com/atom/ns#' term='wireless'/><title type='text'>[WiMAX] Fundamentals of WiMAX - (6)</title><content type='html'>We have introduced the basic idea of &lt;a href="http://jinghaoxu.blogspot.com/2007_06_01_archive.html"&gt;OFDM&lt;/a&gt; before. In this post, we will discuss OFDMA (Orthogonal Frequency Division Multiple Access) in Q&amp;A style. &lt;br /&gt;&lt;br /&gt;Q: What's the relationship between OFDM and OFDMA? &lt;br /&gt;A: OFDMA can be considered as a version of OFDM optimized for multiple users. The basic idea behind OFDMA is &lt;strong&gt;Sub-Channelization&lt;/strong&gt;, i.e. assigning subsets of subcarriers to different users.&lt;br /&gt;&lt;br /&gt;Q: What's the advantage of OFDMA over OFDM?&lt;br /&gt;A: We know OFDM has immuity to frequency-selective fading channel because it breaks a single high data rate stream into multiple low data rate streams, thereby the subcarrier's bandwidth is smaller than the coherence bandwidth of the channel. For a wireless system with multi users, the total system resources are shared by all users. However, in one time slot, OFDM only assigns the whole resource to only one user, i.e. one user occupies all subcarriers in one time. This makes OFDM not efficient in resource allocation. A new multiple-access technique becomes necessary. This is the purpose of OFDMA. By allowing users share subcarriers and time slots,  additional flexibility can be provided by OFDMA: &lt;strong&gt;multi-user diversity&lt;/strong&gt;. In addition, adpative modulation can be used in OFDMA for different users according to channel condition. &lt;br /&gt;&lt;br /&gt;Q: How is the 'Sub-Channelization' realized?&lt;br /&gt;A: In OFDMA, the sub-carriers are divided into groups of sub-carriers. Each group is called a sub-channel. The sub-carriers that form a sub-channel need not be continuous. Based on their channel conditions and QoS requirements, different sub-channels can be assigned (scheduled) to different users. This multiple access is performed before the IFFT operation, thereby the scheduling algorithm used for OFDMA is realized in both frequency and time domain. &lt;br /&gt;&lt;br /&gt;(to be continued)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-6754288472170166835?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/6754288472170166835/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=6754288472170166835' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6754288472170166835'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6754288472170166835'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/09/fundamentals-of-wimax-6.html' title='[WiMAX] Fundamentals of WiMAX - (6)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-4506901945539790012</id><published>2007-08-02T19:07:00.000-04:00</published><updated>2007-09-02T09:26:05.681-04:00</updated><title type='text'>Redirect homepage too fast makes cookie setting failed in IE7</title><content type='html'>Yesterday I got a problem of setting cookies with Javascript in IE7. The cookie string was always generated successfully, but the cookie could not be stored by IE7. I set the privacy level of IE7 to "Accept all cookies", but it doesn't work yet. A simplified demo of the Javasript code is listed below:&lt;br /&gt;&lt;font size='3'&gt;&lt;br /&gt;&lt;table border="1" cellpadding="0" cellspacing="0" bgcolor="#eeeeee"&gt;&lt;br /&gt;&lt;tr&gt;  &lt;br /&gt;&lt;td valign="top" align="left"&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;font color="#000000"&gt;&amp;lt;script&amp;nbsp;language=&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;JavaScript&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;var&amp;nbsp;name=&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;visitor&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;var&amp;nbsp;value=Math.random&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;var&amp;nbsp;today&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Date&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;var&amp;nbsp;expires=&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;new&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;Date&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;today.getTime&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;+&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#990000"&gt;86400&lt;/font&gt;&lt;font color="#000000"&gt;*&lt;/font&gt;&lt;font color="#990000"&gt;1000&lt;/font&gt;&lt;font color="#000000"&gt;))&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;var&amp;nbsp;path=&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;var&amp;nbsp;domain=&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;var&amp;nbsp;secure=&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;var&amp;nbsp;cookieString&amp;nbsp;=&amp;nbsp;name&amp;nbsp;+&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;=&amp;#34;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;+escape&lt;/font&gt;&lt;font color="#000000"&gt;(&lt;/font&gt;&lt;font color="#000000"&gt;value&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;+&amp;nbsp;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;(&amp;nbsp;(&lt;/font&gt;&lt;font color="#000000"&gt;expires&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;?&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;;expires=&amp;#34;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;+&amp;nbsp;expires.toGMTString&lt;/font&gt;&lt;font color="#000000"&gt;()&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;:&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;+&amp;nbsp;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;(&amp;nbsp;(&lt;/font&gt;&lt;font color="#000000"&gt;path&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;?&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;;path=&amp;#34;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;+&amp;nbsp;path&amp;nbsp;:&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;+&amp;nbsp;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;(&amp;nbsp;(&lt;/font&gt;&lt;font color="#000000"&gt;domain&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;?&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;;domain=&amp;#34;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;+&amp;nbsp;domain&amp;nbsp;:&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;+&amp;nbsp;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;(&amp;nbsp;(&lt;/font&gt;&lt;font color="#000000"&gt;secure&lt;/font&gt;&lt;font color="#000000"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;?&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;;secure&amp;#34;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;:&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;)&lt;/font&gt;&lt;font color="#000000"&gt;;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;document.cookie&amp;nbsp;=&amp;nbsp;cookieString;&lt;/font&gt;&lt;br /&gt;&lt;font color="#000000"&gt;&amp;lt;/script&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#000000"&gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;META&amp;nbsp;HTTP-EQUIV=&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;Refresh&amp;#34;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;CONTENT=&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;0;&amp;nbsp;URL=http://www.google.com&amp;#34;&lt;/font&gt;&lt;font color="#000000"&gt;&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;/html&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/td&gt;&lt;br /&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;Finally I found the reason. In order to store the cookies in IE7, you must manually "allow the active contents" to run. &lt;br /&gt;&lt;br /&gt;However, the code &lt;font size="1" color='blue'&gt; &amp;lt;META&amp;nbsp;HTTP-EQUIV=&amp;#34;Refresh&amp;#34;&amp;nbsp;CONTENT=&amp;#34;0;&amp;nbsp;URL=http://www.google.com&amp;#34&amp;gt &lt;/font&gt; refreshes the webpage too fast and thus you cannot unblock the active contents in time. &lt;br /&gt;&lt;br /&gt;For &lt;font size="1" color='blue'&gt; &amp;lt;META&amp;nbsp;HTTP-EQUIV=&amp;#34;Refresh&amp;#34;&amp;nbsp;CONTENT=&amp;#34;n;url&amp;#34 &amp;gt &lt;/font&gt;, &lt;font size="1" color='blue'&gt; n &lt;/font&gt; means the number of seconds to wait before loading the specified URL. If we increase this &lt;font size="1" color='blue'&gt; n &lt;/font&gt; (e.g., let &lt;font size="1" color='blue'&gt; n=10 &lt;/font&gt;), then we will have enough time to unblock the active contents, and then the cookie can be stored successfully.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-4506901945539790012?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/4506901945539790012/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=4506901945539790012' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/4506901945539790012'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/4506901945539790012'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/08/redirect-homepage-too-fast-makes-cookie.html' title='Redirect homepage too fast makes cookie setting failed in IE7'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-6325333591648812223</id><published>2007-07-24T22:25:00.002-04:00</published><updated>2008-04-15T22:12:40.852-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiMAX'/><category scheme='http://www.blogger.com/atom/ns#' term='Wi-Fi'/><category scheme='http://www.blogger.com/atom/ns#' term='wireless'/><title type='text'>[Wireless] Avis Connect - Auto Wi-Fi</title><content type='html'>Last Saturday in San Jose's International airport, I found Avis (a rental car company) is providing a service called auto Wi-Fi. The device looks like a cable modem with two antennas. It says then you can connect to the Internet everywhere you go. The price is $10.95 per day, which is really cheap compared with other paid Wi-Fi services. I'm a little surprised how it works to provide Wi-Fi service when driving, because Wi-Fi is just a short range system and needs to connect itself to a 'real' Internet access network. Mobile WiMAX can connect to Internet direclty but as I know currently the WiMAX network is still under construction. &lt;br /&gt;&lt;br /&gt;When I came back home, I checked the Internet and found the answer: it is a combination of a Wi-Fi router and a high-speed cellular modem. The access to the Interent uses a patent-pending, enhanced-reception technology from Autonet Mobile, which roams among existing 3G cellular networks and can switch seamlessly between neighboring networks and high/low-speed connections as needed without interrupting the session.  This idea is pretty smart. &lt;br /&gt;&lt;br /&gt;Autonet promises the service will work on 95 percent of U.S. roads in the future. It sounds pretty good. Next time for traveling by car, I will have a shot and check how the service is going.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-6325333591648812223?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/6325333591648812223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=6325333591648812223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6325333591648812223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/6325333591648812223'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/07/avis-connect-auto-wi-fi.html' title='[Wireless] Avis Connect - Auto Wi-Fi'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-3043039038739880084</id><published>2007-07-12T02:25:00.001-04:00</published><updated>2008-04-15T22:13:23.417-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiMAX'/><category scheme='http://www.blogger.com/atom/ns#' term='MAC'/><category scheme='http://www.blogger.com/atom/ns#' term='QoS'/><category scheme='http://www.blogger.com/atom/ns#' term='wireless'/><title type='text'>[WiMAX] Fundamentals of WiMAX - (5)</title><content type='html'>In this post, let's take a quick look of the standardizations of WiMAX. &lt;br /&gt;&lt;br /&gt;IEEE 802.16 Group was formed in 1998, its inital focus is to develop an air-interface standard for a LOS-based point to mulitpoint wireless broadband system working in 10G-66GHz band. In 2001, the original 802.16 standard was completed. After that, the task group produced 802.16a, which is an amendment to 802.16. This 802.16a is for NLOS applications in the 2G-11GHz band. Further revision is IEEE 802.16-2004 (fixed WiMAX), which replaced all previous specifications and formed the first version of WiMAX standard. It targeted fixed applications. In order to support mobile services, in 2005 a new amendament to IEEE 802.16-2004 called IEEE 802.16e-2005 (Mobile WiMAX) was approved by IEEE. &lt;br /&gt;&lt;br /&gt;In short, WiMAX uses OFDM in the physical layer. The difference of the two specifications is: IEEE 802.16-2004 uses fixed-FFT-size OFDM, but IEEE 802.16e-2005 uses scalable OFDMA. Therefore, for fixed WiMAX, because FFT size is fixed, the subcarrier spacing will increase with larger bandwidth, and then the symbol time will decrease. It implies that a larger portion of OFDM subcarriers is needed as guard time to overcome delay spread of the channel, which means spectral efficiency is lowered. In the contrast, for mobile WiMAX, the subcarrier spacing is fixed but the FFT size is adjustable. This scheme can be used to balance to requirements of delay spread and Doppler spread of the channel for different operating environments. &lt;br /&gt;&lt;br /&gt;In addition to OFDM, in physical layer WiMAX also supports some optional advanced techniques for increasing the link performance and reliability. These techniques  include powerful FEC - Forward Error Correction coding (such as Turbo coding and LDPC - Low Density Parity Check code, which is very close to the Shannon channel capacity), channel interleaving, multiple antenna techniques - MIMO (please refer to &lt;a href="http://jinghaoxu.blogspot.com/2007/05/fundamentals-of-wimax-3.html"&gt;Fundamentals of WiMAX - (3)&lt;/a&gt; ) and adaptive modulation. From here you can see that WiMAX almost integreted the most popular and advanced techniques of digital communications together. This is an advantage of creating a new system, because you do not have too much back-compatibility issues to take into account.&lt;br /&gt;&lt;br /&gt;Another big portion of WiMAX's standard is specifying the MAC layer functions between the lower physical layer and the upper network and transport layers. The MAC layer should be able to accommodate different traffic types, support QoS (Quality of Service), provide security and mobility and so on. Those are just common functions and are considered in almost every wireless system. The distinct part of WiMAX's MAC layer from other similar systems is on the scheduling and channel-access schemes. In downlink, the Base Station allocates dedicated or shared resources periodically to each subscriber station. Then each MS will use this allocated rresource to request bandwidth. This procedure is called &lt;em&gt;&lt;strong&gt;Polling&lt;/strong&gt;&lt;/em&gt;. Polling can be done with unicast or multicast. In uplink, WiMAX specifies a contention access and resolution scheme for multiple MSs accessing the shared resource. If one MS already has an allocation for traffic sending, it will not be polled. But it can be allowed to request more bandwidth.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-3043039038739880084?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/3043039038739880084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=3043039038739880084' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3043039038739880084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3043039038739880084'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/07/fundamentals-of-wimax-5.html' title='[WiMAX] Fundamentals of WiMAX - (5)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-2244519876973356880</id><published>2007-07-05T21:07:00.002-04:00</published><updated>2008-04-04T12:22:30.161-04:00</updated><title type='text'>Is iPhone a phone?</title><content type='html'>The long rumored iPhone has finally arrived. Someone tore down the iPhone and found the processor is using ARM chips, the ROM and RAM are from Samsung, and the touch screen is made by Epson Imaging Device Corp. They estimated the hardware cost of 8GB iPhone will be about $270, which means the margin is about $330. Of course the margin cannot be that high, because the development cost is not taken into account. But it can be anticipated that the profit will be considerable.&lt;br /&gt;&lt;br /&gt;So many reviews have been posted on the Internet officially by some evaluation groups or personally by Apple fans after June 29. No doubt some Apple fans shouted acclaims and some others attacked its shortcomings severely. I cannot afford buying an iPhone, but I'll try to give my two cents here based on the reviews I have read recently.&lt;br /&gt;&lt;br /&gt;Basically, iPhone is not just a cell phone, it is even not just a smart phone. It innovates the UI (user interface) in a revolutionary way, which makes it so distinct. Although it lacks some functions that some ordinary handsets or smart phones are supporting, such as no voice dialing, no speed dialing, no games, only supports GSM and EDGE etc, its defects cannot obscure the virtues. The reason is that Apple does not have too much experience and technique accumulations on cell phone design, but it grows fast. &lt;br /&gt;&lt;br /&gt;Shortly put, the applications of iPhone can be enhanced, the bugs can be fixed, and the services can be enriched gradually. They will not be problems as long as people have belief on it. Especially from the view of the psychology, Americans love to see a burgeoning force challenges the conventional world and finally gets the success (Google is a lively example). Of course, those big guys in handset industry will not await their dooms. They will fight back definitely. For customers, this will always be a good news. For Apple, the next generation iPhone will be critical and crucial. People can forbear the weakness even flaw of the new product, but cannot tolerate them again. I guess Apple alreay noticed this kind of issue. So, we'll see.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-2244519876973356880?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/2244519876973356880/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=2244519876973356880' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2244519876973356880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2244519876973356880'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/07/is-iphone-phone.html' title='Is iPhone a phone?'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-3602063872002424054</id><published>2007-06-19T18:51:00.001-04:00</published><updated>2008-04-17T16:04:48.658-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiMAX'/><category scheme='http://www.blogger.com/atom/ns#' term='cyclic prefix'/><category scheme='http://www.blogger.com/atom/ns#' term='OFDM'/><category scheme='http://www.blogger.com/atom/ns#' term='wireless'/><title type='text'>[WiMAX] Fundamentals of WiMAX - (4)</title><content type='html'>Today we are talking about another important technique used in WiMAX - OFDM. &lt;br /&gt;&lt;br /&gt;From the characteristic of the channel propagation in wireless environment, we know that delay spread caused by multipath fading will generate severe Inter Symbol Interference (ISI) for high data rate transmission, because the symbol time is inversely proportional to the data rate. As we mentioned before &lt;a href="http://jinghaoxu.blogspot.com/2007/05/why-ofdm-for-wimax-and-b3g.html"&gt;(Why OFDM for WiMAX and B3G?)&lt;/a&gt;, you can use CDMA technology with Rake receiver to solve this problem, but it elicits two new problems: one is that the complexity is high, another is that you may need a huge bandwidth to get the essential spreading gain. For WiMAX system, the second problem is more difficult to handle with. But for UWB (Ultra Wide Band) system, it is achievable. So that's why one of the UWB's candidate PHY proposal is using spreading spectrum technique (DS-UWB). &lt;br /&gt;&lt;br /&gt;Fortunately, a smart multi carrier modulation scheme called OFDM can support high data rate effectively. The basic idea of OFDM is simple: if you can not change the channel, you can change the signal to adapt to it. &lt;br /&gt;&lt;br /&gt;We know in order to have a channel that does not have ISI, the symbol duration should be larger than the delay spread (or equivalently, the signal bandwidth should not exceed the coherence bandwidth). If we can divide the high rate date stream into &lt;em&gt;M&lt;/em&gt; lower-rate substreams, then each substream will have larger subsymbol duration. If the subsymbol duration exceeds the delay spread, it hence is ISI free. Euqivalently, in this scenario, each substream's bandwidth is lower than the coherence bandwidth of the channel. However, simply dividing the high rate stream to lower-rate streams is just like the conventional mulit carrier technique, you have to insert guard band between subcarriers, which leads to very inefficient use of the available spectrum. OFDM solves this problem by overlapping subcarriers. Of course, you can not overlap subcarriers arbitrarily, because overlapping introduces crosstalk between subcarriers. But, if those subcarriers can overlap in orthogonality, great, the crosstalk vanishes! &lt;br /&gt;&lt;br /&gt;A block diagram of OFDM system is shown in the following figure:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_bmgcIB-XFnQ/RoLq13d7v2I/AAAAAAAAAAk/6aXOQXospBk/s1600-h/Ofdm.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp2.blogger.com/_bmgcIB-XFnQ/RoLq13d7v2I/AAAAAAAAAAk/6aXOQXospBk/s320/Ofdm.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5080881540770807650" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The modulator part is illustrated as follows:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_bmgcIB-XFnQ/RoLroXd7v3I/AAAAAAAAAAs/yDjFE4AiQNQ/s1600-h/Ofdm_mod.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp0.blogger.com/_bmgcIB-XFnQ/RoLroXd7v3I/AAAAAAAAAAs/yDjFE4AiQNQ/s320/Ofdm_mod.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5080882408354201458" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And a simplified baseband model of passing an OFDM signal through the channel is demonstrated in the next figure:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_bmgcIB-XFnQ/RoLsMHd7v4I/AAAAAAAAAA0/KhUgI6-l2Ao/s1600-h/ofdm_baseband.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp3.blogger.com/_bmgcIB-XFnQ/RoLsMHd7v4I/AAAAAAAAAA0/KhUgI6-l2Ao/s320/ofdm_baseband.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5080883022534524802" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Finally, the time-frequency block structure of the OFDM signal is shown in the figure below (where CP means cyclic prefix, whose length should be larger than the maximum delay spread of the channel):&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_bmgcIB-XFnQ/RoLtZ3d7v5I/AAAAAAAAAA8/nf9xLCyI6r8/s1600-h/ofdm_block.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp2.blogger.com/_bmgcIB-XFnQ/RoLtZ3d7v5I/AAAAAAAAAA8/nf9xLCyI6r8/s320/ofdm_block.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5080884358269353874" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-3602063872002424054?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/3602063872002424054/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=3602063872002424054' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3602063872002424054'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3602063872002424054'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/06/fundamentals-of-wimax-4.html' title='[WiMAX] Fundamentals of WiMAX - (4)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_bmgcIB-XFnQ/RoLq13d7v2I/AAAAAAAAAAk/6aXOQXospBk/s72-c/Ofdm.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-562930322810304700</id><published>2007-06-07T23:03:00.001-04:00</published><updated>2008-04-17T16:06:25.381-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiMAX'/><category scheme='http://www.blogger.com/atom/ns#' term='LTE'/><category scheme='http://www.blogger.com/atom/ns#' term='UMB'/><category scheme='http://www.blogger.com/atom/ns#' term='OFDMA'/><category scheme='http://www.blogger.com/atom/ns#' term='Wibro'/><category scheme='http://www.blogger.com/atom/ns#' term='3GPP'/><title type='text'>War without smoke - LTE, UMB, WiMAX...</title><content type='html'>"OFDMA TDD WMAN", the new name of a subset of WiMAX, was recommended by ITU-R as an IMT-2000 radio technology last week. It's a good news for WiMAX. Someone said: WiMax Gets ITU Standards Boost. Yes, it is. But, still a long way to go. &lt;br /&gt;&lt;br /&gt;Let's take a look at how many candidate technologies we may have for the future:&lt;br /&gt;LTE of 3GPP, UMB of 3GPP2, WiMAX, Mobile WiMAX/WiBro, IEEE802.20...&lt;br /&gt;&lt;br /&gt;Ericsson said they abandoned WiMAX and would focus on LTE only, Qualcomm must be supporting UMB and they claimed they have many patents on OFDM/WiMAX, they also proposed IEEE802.20, Korea will continue working on the WiBro, even in the wired acccess area, there will be some Passive Optical Networks (PON) emerging in the future...&lt;br /&gt;&lt;br /&gt;So who will win this war? Nobody knows, and it is impossible that one of them beats all others. I think some of them must be co-existing. But, the following answer should always be true: " It's something unpredictable but in the end USER's right. " (Lyrics of the Time of your life by Green Day) :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-562930322810304700?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/562930322810304700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=562930322810304700' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/562930322810304700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/562930322810304700'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/06/war-without-smoke-lte-umb-wimax.html' title='War without smoke - LTE, UMB, WiMAX...'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-5249292032749506077</id><published>2007-06-04T20:11:00.001-04:00</published><updated>2007-06-04T21:32:07.909-04:00</updated><title type='text'>Capacity of ad hoc networks</title><content type='html'>Unlike the conventional cellular networks with single hopping from every terminal to&lt;br /&gt;the base station, traffic in ad hoc networks may be relayed via intermediate nodes to the distant destination. The advantage of this multi-hop communication scheme is: the required transmission power can be reduced exponentially with shortened transmission distance, and more concurrent transmissions may be available in the whole network because of spatial reuse of the resource, such as frequency or channelizing codes. However, it is very difficult to achieve the best of both worlds. With shortened transmission link, the number of hops from the source to the destination increases too. Partial system bandwidth must be used to deliver those relayed traffic. On the other hand, more concurrent transmissions result in increased number of interferers. Therefore, one of the fundamental challenges in ad hoc network research is what capacity can be achieved and how to achieve it.&lt;br /&gt;&lt;br /&gt;Capacity of a network means the theoretical bounds on the performance under perfect network operation. Generally speaking, capacity or throughput analysis of wireless ad hoc networks may be explored in the following three ways:&lt;br /&gt;&lt;br /&gt;1) The first solution is to find the exact capacity region (defined as closure set of feasible rates) in the perspective of information theory as in the conventional cellular network. &lt;br /&gt;&lt;br /&gt;However, it is very difficult to obtain the exact capacity region because multiple nodes in the network can cooperate in very complicated and sophisticated ways. As an example, even the capacity of the simplest relay channel, which consists of just three nodes, a source, a relay and a destination, is not fully solved yet.&lt;br /&gt;&lt;br /&gt;Recently, a breakthrough on the network information theory was obtained in [Xie 04]. With the assistance of the Max-Flow Min-Cut lemma, the authors indicate that the network capacity is always upper bounded by sum of total power used by the transmissions of all the nodes in the network.&lt;br /&gt;&lt;br /&gt;2) The second method is to study the long term available throughput coarsely, e.g. analyzing the asymptotic capacity and scaling law with respect to the network size. &lt;br /&gt;&lt;br /&gt;This method recently gained much attention, although it is coarser than the first one. The well-known result is given by [Gupta 00], who demonstrates that capacity per user goes to zero as the number of the nodes per unit area goes to infinity. This is a pessimistic result, because it means large ad hoc network’s capacity is poor.&lt;br /&gt;&lt;br /&gt;After Gupta’s work, many people engaged in the ad hoc network capacity and tried to find a better solution. One important paper is the one written by Grossglauser and David Tse in 2002. The policy is, introduce the mobility of nodes into traffic transmission. Source node will first transfer to near relays, and those relays will not transmit to desired destinations until they move close. The throughput can be increased to the order of N, but the delay is too high.&lt;br /&gt;&lt;br /&gt;Recently an interesting paper [Jafar-tit05] shows that too much mobility may limit the capacity of ad hoc networks. His argument is when mobility is too high, the node cannot track the channel in time to get the instantaneous CSI, then makes it difficult to distinguish between nearest neighbors and distant nodes at each moment.&lt;br /&gt;&lt;br /&gt;3) The third one is measuring the practical throughput under some specific configurations by numerical simulation. &lt;br /&gt;&lt;br /&gt;Many great simulation platforms have been developed for this purpose and a lot of research work can be found in this area. Some well-known examples are Network Simulator 2 (NS2), OPNet, QualNet (commercial version of Glomosim) etc. &lt;br /&gt;&lt;br /&gt;NS2 is free to use, but OPNet and QualNet require licenses. I used NS2 for about more than one year. The learning curve is a little bit long. If you just want to use existing funcational modules to run simulation, it's not too hard. You can use TCL/OTCL to set up environment and parameters. If you want to modify the existing modules or add something new, you have to know how to interface TCL/OTCL with C++, because the kernel of NS2 is programed in C++. &lt;br /&gt;&lt;br /&gt;However, when I used it, the version 2.28 has a problem in the interference and noise calculation in the physical layer: the SNIR (Signal to Noise and Interference ratio) is not recalculated every time the interference changes. A paper given by Mineo Takai addressed this problem in depth. Fading channel was not supported either. Someone made an extension with Rayleigh and Ricean fading but it only worked with old version. Fortunately, I found a solution by modifying some lines of the source code. Moreover, a difficult thing is how to compare your results with other guys'. Especially when you modified the program, no one knows if your modification can be justified (I think most of the simulators have the similar problem, but commercial platforms may be better because they keep the consistency well). So finally I abandoned it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-5249292032749506077?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/5249292032749506077/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=5249292032749506077' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/5249292032749506077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/5249292032749506077'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/06/capacity-of-ad-hoc-networks.html' title='Capacity of ad hoc networks'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-3959337004884861161</id><published>2007-05-27T22:47:00.001-04:00</published><updated>2008-04-17T16:07:17.527-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WiMAX'/><category scheme='http://www.blogger.com/atom/ns#' term='OFDM'/><category scheme='http://www.blogger.com/atom/ns#' term='MIMO'/><category scheme='http://www.blogger.com/atom/ns#' term='wireless'/><category scheme='http://www.blogger.com/atom/ns#' term='cdma2000'/><title type='text'>[WiMAX] Fundamentals of WiMAX - (3)</title><content type='html'>Today we are talking about one of the two core technologies of WiMAX: Multiple Antenna Techniques (let's abbreviate in MAT). Another important one is OFDM, which will be deferred to next topic. Like all 3G systems picked CDMA, we can anticipate that perhaps almost all upcoming 4G systems will employ OFDM and MIMO (Multiple Input Multiple Output) techniques. (Recent an interesting news is that &lt;a href="http://www.pcworld.com/article/id,131732-page,1/article.html"&gt;Qualcomm just gave a tough talk on the patents of 4G.&lt;/a&gt; ) &lt;br /&gt;&lt;br /&gt;What can MAT provide? Generally speaking, MAT supports &lt;br /&gt;1) spatial diversity, &lt;br /&gt;2) beamforming,&lt;br /&gt;3) and spatial multiplexing. &lt;br /&gt;&lt;br /&gt;In old times (1970s), people only use multiple antenna in receiver owing to the cost and size consideration. In this case, with &lt;strong&gt;selection combining&lt;/strong&gt; or &lt;strong&gt;maximal ratio combining&lt;/strong&gt; (MRC), the performance under fading environment can be improved significantly due to &lt;strong&gt;receive diversity&lt;/strong&gt;. &lt;br /&gt;&lt;br /&gt;Later, people noticed that using MAT with &lt;strong&gt;beamforming&lt;/strong&gt; can concentrate the power of the desired signal in a specific direction and lower down the interference to other links away from this direction. This is especially useful for multi user network. They call it smart antenna technique. One example is the TD-SCDMA system in 3G area. &lt;br /&gt;&lt;br /&gt;In the late of 1990s, a key breakthrough was made for MAT. &lt;strong&gt;Transmit diversity&lt;/strong&gt; schemes were invented, such as the space-time block code (STBC). Now the promising area of MAT is the &lt;strong&gt;spatial multiplexing&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;For the receive diversity, you can find it from most of the wireless communication books. So we will focus our concentration on the transmit diversity and beamforming.&lt;br /&gt;&lt;br /&gt;1) Transmit diversity&lt;br /&gt;There are two types of transmit diversity, one is &lt;strong&gt;open-loop&lt;/strong&gt;, another one is &lt;strong&gt;closed-loop&lt;/strong&gt;. Open-loop means at the transmitter you don't need a feedback for the channel state from the receiver. On the contrary, closed-loop requires it. Thus you should guarantee the channel is with reciprocity. In some cases, you can assume the channel to be reciprocal, although it isn't. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Open-loop transmit diversity&lt;/strong&gt;&lt;br /&gt;The most popular open-loop transmit diversity scheme is STBC, where a special coding scheme (called Alamouti code, name of the inventor, who is currently the &lt;a href="http://www.intel.com/pressroom/kits/bios/salamouti.htm"&gt;CTO of Intel's Mobility Wireless Group&lt;/a&gt;) is used in the transmitter. In short, a Nt*Nr STBC achieves the same diversity order and data rate as a Nr*Nt receive diversity system with MRC, but with a 10*log_10(Nt) transmit power penalty because of Nt transmit antennas. &lt;br /&gt;&lt;br /&gt;For WiMAX or other OFDM-based system, the space/time coding can be coded over adjacent subcarriers rather than time slots.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Closed-loop transmit diversity&lt;/strong&gt;&lt;br /&gt;In this case, channel state information(CSI) is required at the transmitter. Because channel changes quickly in a highly mobile scenario, it is difficult to track the channel state in time and feedback it to the transmitter. Therefore, closed-loop transmit diversity tends to be suitable for fixed or low-mobility scenarios. Two important closed-loop schemes are: transmit selection diversity (TSD) and linear diversity precoding (LDP).&lt;br /&gt;&lt;br /&gt;In TSD, only a subset of Nt transmit antennas are selected with good CSI, thereby comparing with STBC, TSD has less transmit power penalty because fewer transmit signals are sent. &lt;br /&gt;&lt;br /&gt;In LDP, a linear precoder is used at the transmitter and a linear postcoder is applied at the receiver. They are used to improve the link reliability and can achieve higher SNR than the open-loop schemes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-3959337004884861161?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/3959337004884861161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=3959337004884861161' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3959337004884861161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3959337004884861161'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/05/fundamentals-of-wimax-3.html' title='[WiMAX] Fundamentals of WiMAX - (3)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-1392930788898085322</id><published>2007-05-25T15:39:00.000-04:00</published><updated>2007-05-25T23:23:43.508-04:00</updated><title type='text'>Free talk - Analogy between wireless network and society</title><content type='html'>Today when I was on the metro bus, an idea jumped into my mind: there is some similarity between the wireless network and the human society.&lt;br /&gt;&lt;br /&gt;For example, a sensor network with data aggregation is as a community, a cellular network is like a country ruled by a dictatorial government, a pure ad hoc network can be considered with Anarchism (means abolition of governments), and a network with multiple access points is like a society with democracy (some nodes are 'elected' as access points).&lt;br /&gt;&lt;br /&gt;The interesting thing is, what is good for the administration of the society, republic, federal , democracy or autocracy? Similarly, which network topology is effective for a wireless network?  Why the existing mobile networks use the cellular architecture? Why most 802.11 networks are configured in IBSS (Infrastructure Basic Service Set)?  Think about it...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-1392930788898085322?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/1392930788898085322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=1392930788898085322' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1392930788898085322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1392930788898085322'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/05/free-talk-analogy-between-wireless.html' title='Free talk - Analogy between wireless network and society'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-7577484650826082312</id><published>2007-05-12T13:55:00.002-04:00</published><updated>2008-04-17T16:04:10.862-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LTE'/><category scheme='http://www.blogger.com/atom/ns#' term='WCDMA'/><category scheme='http://www.blogger.com/atom/ns#' term='OFDM'/><category scheme='http://www.blogger.com/atom/ns#' term='B3G'/><category scheme='http://www.blogger.com/atom/ns#' term='3G'/><title type='text'>[Wireless] Why OFDM for WiMAX and B3G?</title><content type='html'>In the beginning of 3G (Third Generation) era, CDMA technique was widely employed for most systems. For instance, 3GPP selected WCDMA (Wideband CDMA) for FDD mode, TD-SCDMA for TDD mode; 3GPP2 extended cdmaone to CDMA2000. The main reason is to support higher data rate wireless service in 3G systems than that in 2G systems.&lt;br /&gt;&lt;br /&gt;Wideband CDMA system has a large bandwidth, which can be used to achieve frequency diversity. However, there exists a contradiction between the large bandwidth and high data rate which can be shown in the following simple diagram:&lt;br /&gt;&lt;br /&gt;Wide bandwidth -&gt; frequency selective channel -&gt; causes large delay spread in time domain&lt;br /&gt;High data rate -&gt; small symbol interval -&gt; experiences serious Inter Symbol Interference&lt;br /&gt;&lt;br /&gt;For CDMA system, in order to combat this multipath delay spread, usually it has to resort to the sophisticated RAKE receivers, which resolves multipath using muliple fingers.&lt;br /&gt;&lt;br /&gt;However, when wireless system goes to the broadband era, wideband CDMA may not be adequate. Even 3GPP proposed HSPDA/HSUPA to support data rate up to 14.4M/5.8Mbps in 5MHz channel , 3GPP2 proposed 1xEV-DO for data rate 3.1M/1.8Mbps (revision A), 4.9M/1.8Mbps (revision B) in 1.25MHz channel, their capability of supporting much higher data rate is limited. One reason is that they have to use multiple codes simultaneously, which may result in self-interference.&lt;br /&gt;&lt;br /&gt;That's why in B3G (Beyond 3G), LTE (Long-term evolution) of 3GPP and AIE (Air Interface Evolution) of 3GPP2 both pick OFDM combining MIMO instead of CDMA. Similarly, in IEEE802.11 series, the low date rate is working on CDMA (802.11b) but high date rate uses OFDM (802.11g and 802.11a). WiMAX is also using OFDM.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-7577484650826082312?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/7577484650826082312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=7577484650826082312' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/7577484650826082312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/7577484650826082312'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/05/why-ofdm-for-wimax-and-b3g.html' title='[Wireless] Why OFDM for WiMAX and B3G?'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-1994382621128360749</id><published>2007-05-08T22:05:00.000-04:00</published><updated>2008-01-25T20:44:35.613-05:00</updated><title type='text'>[WiMAX] Fundamentals of WiMAX - (2)</title><content type='html'>In this part, we are going to give an overview of the wireless channel that may be experienced by WiMAX.&lt;br /&gt;&lt;br /&gt;Generally speaking, the basic and important issues of wireless channel contain three aspects: pathloss, large-scale Shadowing and small-scale fading. You can find detailed descriptions of them in most of the books regarding wireless communications (chapter 4 and 5 of [1]). In summary, pathloss is inversely propotional to the distance between the transmitter and the receiver, Shadowing is mainly caused by obstructions within the propagation environment and is often log-normal distributed, small-scale fading is caused by multipath reflections (modeled by delay spread or coherence bandwidth) or motion between the transmitter and the receiver (modeled by Doppler frequency shift or coherence time).&lt;br /&gt;&lt;br /&gt;So we will skip those fundamentals issues and assume that you have already known them very well. However, channel also varies over space if multiple antennae are used. Multiple antenna techniques emerged as a breakthrough in the last several years and some traditional books may lack of description on this part, thereby next we will give an outline of the spatial aspect of wireless channels.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Angular Spread&lt;/strong&gt;&lt;/p&gt;Like delay spread or Doppler spread, a parameter used to model the channel in space is the angular spread. It refers to the statistical distribution of the arriving signal's angle. A small angular spread means the received signal's energy is more focused, which implies less statistical diversity; contrarily, large angular spread means more statistical diversity available.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Coherence Distance&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The dual of angular spread is coherence distance. A coherence distance &lt;em&gt;Dc&lt;/em&gt; means that any physical positions separated by &lt;em&gt;Dc&lt;/em&gt; have an uncorrelated received signal amplitude and phase. Coherence distance is often related to the wave length. Thus, higher frequency system has shorter coherence distance.&lt;br /&gt;&lt;br /&gt;Coherence distance is often used to specify how far apart antennae should be separated to make received signals statistically independent. Small coherence distance means antenna array can be easily applied to provide rich diversity. This is particularly useful for mobile terminals which has the size constraint. Large coherence distance implies that large separation between two antennas is needed. In this case, it would be preferable to use beamforming with antenna array.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Channel model for OFDM&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Since WiMAX is using OFDM, the channel model with multidimension correlation should be considered. When channel is highly frequency selective, it requires a large number of closely spaced subcarriers to combat the ISI (Inter Symbol Interference). On the other hand, when the channel is with large Doppler frequency shift (high mobility), it will degrade the subcarrier orthogonality. In the frequency domain, it will cause significant ICI (Inter Carrier Interference) as subcarriers become more closely spaced.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Emperical model&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;An emperical channel model for MIMO was proposed and developed by 3GPP (Third Generation Partnership Project). It is described in the technical report TR 25.996 [2]. This model can be used for systems such as WiMAX, 802.11n and 802.20 which use MIMO techniques.&lt;br /&gt;&lt;br /&gt;Reference:&lt;br /&gt;[1] Theodore S. Rappaport, "Wireless Communications: Principles and Practice (2nd Edition)," Prentice Hall PTR, December, 2001&lt;br /&gt;[2] Spatial channel model for Multiple Input Multiple Output (MIMO) simulations &lt;a href="http://www.3gpp.org/ftp/Specs/archive/25_series/25.996/"&gt;http://www.3gpp.org/ftp/Specs/archive/25_series/25.996/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-1994382621128360749?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/1994382621128360749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=1994382621128360749' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1994382621128360749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/1994382621128360749'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/05/fundamentals-of-wimax-2.html' title='[WiMAX] Fundamentals of WiMAX - (2)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-5634994067923699786</id><published>2007-05-06T19:48:00.000-04:00</published><updated>2008-01-25T20:44:21.653-05:00</updated><title type='text'>[WiMAX] Fundamentals of WiMAX - (1)</title><content type='html'>&lt;p&gt;WiMAX (Worldwide Interoperability for Microwave Access) is one kind of wirless broadband access technology. In my country, China, WiMAX is going to be deployed for the 2008 Olypmic games. Actually, in China there is another technology called McWill (Multicarrier Wireless internet Local Loop), which is a synchronous CDMA system using Smart Antenna , SWAP signaling , synchronous CDMA and Software Radio. This McWill is developed by a Chinese company. I remembered in the end of 2006, the news said McWill would be used for 2008 Olympic games. However, just after several months, the latest news says that WiMAX is authorized by the committe of the Olympic games and China Mobile is goint to deploy it in 2008. It looks like McWill lost the game. It is really a pity. &lt;/p&gt;&lt;p&gt;Ok, let us go back to our topic and concentrate on techniques. From today, I'm going to give a series of introduction of WiMAX, mainly focuses on its fundamental issues, such as overview, history, technicall challeges, physical layer, MAC layer etc. I think it also helps me consolidate my knowledge on WiMAX.&lt;br /&gt;&lt;br /&gt;History of WiMAX&lt;br /&gt;&lt;br /&gt;Before WiMAX, there already exist many wireline broadband access techniques, such as DSL(Digital Subscriber Line), cable modem, FTTP(Fiber to the premises ) and VDSL. This market grows quickly. When I came to the US in 2001, the rate of Verizon's is about 768Kbps. Now I'm using Comcast's cable modem with rate 5Mbps. Recently, Verizon is promoting its FIOS system which is said to support rate at 15-40Mbps.&lt;br /&gt;&lt;br /&gt;Later, people found it is necessary to provide broadband access service in wireless, because it offers additional benifits and convenience. For example, it may be easier to install than wire-line access, the cost may be lower, it can be portable and mobile.&lt;br /&gt;&lt;br /&gt;Generally speaking, wireless broadband access can be categorized into two types:&lt;br /&gt;1) Fixed wireless broadband,&lt;br /&gt;2) Mobile broadband.&lt;br /&gt;&lt;br /&gt;As for WiMAX, it has evolved through four stages. [1]&lt;br /&gt;1) Narrowband WLL (Wireless Local Loop) system&lt;br /&gt;2) First generation LOS (Line of Sight) broadband system&lt;br /&gt;3) Second generation NLOS (Non Line of Sight) broadband system&lt;br /&gt;4) Standard-based broadbank system.&lt;br /&gt;&lt;br /&gt;Next, let us take a quick look of those four stages.&lt;br /&gt;&lt;br /&gt;1) Narrowband WLL&lt;br /&gt;&lt;br /&gt;It is mainly based on DECT or CDMA. As I know, WLL on CDMA at 450MHz has been using in China for a long while.&lt;br /&gt;&lt;br /&gt;2) LOS&lt;br /&gt;&lt;br /&gt;In 1990s, &lt;span style="color:#3366ff;"&gt;&lt;a href="http://en.wikipedia.org/wiki/LMDS"&gt;LMDS&lt;/a&gt;&lt;/span&gt;(Local Multipoint Distribution System), works on 2.5 or 3.5GHz. Operator: Nextlink. Now it is almost dead. [2]&lt;/p&gt;&lt;p&gt;In late 1990s, &lt;span style="color:#3366ff;"&gt;&lt;a href="http://en.wikipedia.org/wiki/MMDS"&gt;MMDS&lt;/a&gt;&lt;/span&gt;(Multichannel Multipoint Distribution System), works on 2.5GHz. Operators: MCI, Sprint. &lt;/p&gt;&lt;p&gt;Starting in 2006, MMDS frequencies in the 2110-2155 MHz range are being re-allocated for the Advanced Wireless Services (AWS-1). [3]&lt;/p&gt;&lt;p&gt;3) NLOS&lt;/p&gt;&lt;p&gt;It is proposed to overcome the LOS issue, and improve link performance under multipath conditions. It may use OFDM, CDMA or multiantenna techniques. &lt;/p&gt;&lt;p&gt;4) Standard-based&lt;/p&gt;&lt;p&gt;It is the well-known &lt;span style="color:#6633ff;"&gt;&lt;a href="http://en.wikipedia.org/wiki/Wimax"&gt;IEEE 802.16x&lt;/a&gt; &lt;/span&gt;&lt;span style="color:#000000;"&gt;[4]&lt;/span&gt;, a seriers of standards for Wireless Metropolitan Area Network (WMAN).&lt;/p&gt;&lt;ul&gt;&lt;li&gt;December 2001, IEEE 802.16 standards completed for &gt; 11GHz.&lt;br /&gt;Wireless WAN-SC, uses single carrier modulation techniques. MAC layer is with TDM.&lt;/li&gt;&lt;li&gt;January 2003, IEEE 802.16a standard completed.&lt;br /&gt;Works in the 2GHz to 11GHz range, enables NLOS deployments by using OFDM. MAC is using OFDMA. &lt;/li&gt;&lt;li&gt;June 2004, IEEE 802.16-2004 standard completed and approved.&lt;br /&gt;It replaces 802.16, 802.16a, 802.16c with a single standard. It is also called Fixed WiMAX.&lt;/li&gt;&lt;li&gt;December 2005, IEEE802.16e-2005 approved.&lt;br /&gt;Supports vehicular mobility applications. It is also referred to as Mobile WiMAX.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Similar to 802.11x, IEEE established the specifications for WiMAX but left to the industry the task of converting them into an interoperable standard and the task of certification. WiMAX Forum (analogous as Wi-Fi Alliance) was formed to do those tasks. &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;[1] J.G.Andrews, Arunabha Ghosh and Rias Muhamed, "Fundamentals of WiMAX-understanding Broadband Wireless Networking", Prentice Hall, Feb, 2007&lt;/p&gt;&lt;p&gt;[2] &lt;a href="http://en.wikipedia.org/wiki/MMDS"&gt;http://en.wikipedia.org/wiki/MMDS&lt;/a&gt;&lt;/p&gt;&lt;p&gt;[3] &lt;a href="http://en.wikipedia.org/wiki/LMDS"&gt;http://en.wikipedia.org/wiki/LMDS&lt;/a&gt;&lt;/p&gt;&lt;p&gt;[4] &lt;a href="http://en.wikipedia.org/wiki/Wimax"&gt;http://en.wikipedia.org/wiki/Wimax&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-5634994067923699786?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/5634994067923699786/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=5634994067923699786' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/5634994067923699786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/5634994067923699786'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/05/fundamentals-of-wimax-1.html' title='[WiMAX] Fundamentals of WiMAX - (1)'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-3996236818995164721</id><published>2007-04-28T19:23:00.000-04:00</published><updated>2007-04-28T19:58:58.660-04:00</updated><title type='text'>Export figure to pdf in Matlab</title><content type='html'>In LaTex, if the figure is in pdf format, you can click pdfLaTex just once to generate the output. Otherwise, if the figure is in eps format, you have to click button three times to do the same thing by using the LaTex -&gt; dvi2ps -&gt; ps2pdf workflow.&lt;br /&gt;&lt;br /&gt;The good thing is, Matlab can export figure to pdf format. Unfortunately, when saving a figure to a pdf file in Matlab, you'll find the figure doesn't fit the layout very well, i.e. there is a large margin from the figure to the page boundary. Those margins will be inserted into the LaTex output when you include these pdf figures. &lt;br /&gt;&lt;br /&gt;A solution is:&lt;br /&gt;1) After you plot the figure in Matlab, go to 'File-&gt;Export Setup', input the size of the output you want, e.g. Width: 6 inches, Height: 5 inches. Then click 'Apply to Figure' button.&lt;br /&gt;2) Don't close the 'Export Setup' window. Go to 'File-&gt;Print Preview-&gt;Paper', input the same size in the Width and Height options.&lt;br /&gt;3) Don't close the 'Print Preview' window. Go back to the 'Export Setup' window, and click 'Export', then select pdf format and save it. &lt;br /&gt;4) Check the output pdf file, you'll see it is perfect.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-3996236818995164721?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/3996236818995164721/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=3996236818995164721' title='16 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3996236818995164721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3996236818995164721'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/04/export-figure-to-pdf-in-matlab.html' title='Export figure to pdf in Matlab'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>16</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-3256836086093994089</id><published>2007-04-27T08:48:00.002-04:00</published><updated>2008-03-11T13:16:01.970-04:00</updated><title type='text'>Making Slides Using LaTex</title><content type='html'>Recently I'm preparing for my dissertation slides. I used to create transparencies with PowerPoint because of its simplicity, but it is really difficult to cope with mathmatical equations. You have to reserve space for equations in the text, and if you modify some equations later, you may have to readjust their reserved space one by one.&lt;br /&gt;&lt;br /&gt;So I transfer to LaTex, although I need some time to learn it, it is powerful. It has rich overlay and dynamic effects. The layout, the colors and the fonts can easily be changed. The most important thing for me is that it can merge text and mathematical formulae smoothly and can reuse LaTex codes of my previous papers.&lt;br /&gt;&lt;br /&gt;There are some well-known existing packages for slides making in LaTex, such as Beamer, Proper, Foiltex etc. I didn't spend too much time on investigating and comparing those packages pros and cons. I just select the Beamer.&lt;br /&gt;&lt;br /&gt;After half day's learning, I can create slides with Beamer quickly. Beamer can handle graphics but with less flexibility, e.g. locating the position of figures freely is not that easy. Fortunately, I found another package called 'pstricks' which can do this kind of work easily. However, pstricks does not support PdfLaTex. The workflow of pstricks is LaTex-&gt;dvips-&gt;pspdf. &lt;br /&gt;&lt;br /&gt;The following figure is a demo of the slides created by Beamer.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_bmgcIB-XFnQ/RjH-RSxG2DI/AAAAAAAAAAM/ZeJORquG4v4/s1600-h/SlidesBeamer.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5058103429562816562" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_bmgcIB-XFnQ/RjH-RSxG2DI/AAAAAAAAAAM/ZeJORquG4v4/s320/SlidesBeamer.jpg" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-3256836086093994089?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/3256836086093994089/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=3256836086093994089' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3256836086093994089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/3256836086093994089'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/04/making-slides-using-latex.html' title='Making Slides Using LaTex'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_bmgcIB-XFnQ/RjH-RSxG2DI/AAAAAAAAAAM/ZeJORquG4v4/s72-c/SlidesBeamer.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-5402686776524966285</id><published>2007-04-25T15:30:00.000-04:00</published><updated>2007-05-28T17:00:15.248-04:00</updated><title type='text'>Error LNK2001: unresolved external symbol...</title><content type='html'>Recently, when I used the templates in C++, I got a link error: unresolved external symbol "public: __thiscall ...". My work has three files: fc.h, fc.cpp and main.cpp.&lt;br /&gt;&lt;br /&gt;  &lt;style type="text/css"&gt;&lt;br /&gt;    &lt;!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }--&gt;&lt;br /&gt;  &lt;/style&gt;&lt;br /&gt;&lt;br /&gt;  &lt;tr&gt;&lt;br /&gt;  &lt;!-- start source code --&gt;&lt;br /&gt;   &lt;td nowrap="nowrap" valign="top" align="left"&gt;&lt;br /&gt;    &lt;code&gt;&lt;br /&gt;&lt;font color="#000000"&gt;------------------------------------------------&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#3f7f5f"&gt;//&amp;nbsp;fc.h&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;template&amp;nbsp;&amp;lt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;class&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;T&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;class&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;fc&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;:&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;func&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#3f7f5f"&gt;//&amp;nbsp;end&amp;nbsp;of&amp;nbsp;fc.h//&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;------------------------------------------------&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#3f7f5f"&gt;//&amp;nbsp;fc.cpp&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;template&amp;nbsp;&amp;lt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;class&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;T&amp;gt;fc&amp;nbsp;&amp;lt;&lt;/font&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;class&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;T&amp;gt;::func&lt;/font&gt;&lt;font color="#000000"&gt;()&amp;nbsp;{&amp;nbsp;}&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#3f7f5f"&gt;//&amp;nbsp;end&amp;nbsp;of&amp;nbsp;fc.cpp//&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;------------------------------------------------&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#3f7f5f"&gt;//&amp;nbsp;main.cpp&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;#include&amp;nbsp;&lt;/font&gt;&lt;font color="#2a00ff"&gt;&amp;#34;fc.h&amp;#34;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#7f0055"&gt;&lt;b&gt;int&amp;nbsp;&lt;/b&gt;&lt;/font&gt;&lt;font color="#000000"&gt;main&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;{&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;fc&amp;nbsp;A;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#ffffff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#000000"&gt;A.func&lt;/font&gt;&lt;font color="#000000"&gt;()&lt;/font&gt;&lt;font color="#000000"&gt;;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;}&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;------------------------------------------------&lt;/font&gt;&lt;/code&gt;&lt;br /&gt;    &lt;br /&gt;   &lt;/td&gt;&lt;br /&gt;  &lt;!-- end source code --&gt;&lt;br /&gt;   &lt;/tr&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;However, when I removed the template declaration from the header file, or put all three files just in one body, the link runs smoothly. Finally, I found the reason and the solution of this kind of problem from the Internet [1].&lt;br /&gt;&lt;br /&gt;At least three cases are related to this link error:&lt;br /&gt;1. Forget to define a declared member function, especially the constructor.&lt;br /&gt;2. Static member or class.&lt;br /&gt;3. Using template with splitted declaration and definition.&lt;br /&gt;&lt;br /&gt;For the first scenario, in general, people will not forget to define a member function after the declaration. So this kind of link erro seldom appears. But sometimes people may have declared the constructor but forget the definition and think the system will do it automatically. It is right that system may creat the default constructor if you don't declare it. But this doesn't work when the declaration has been made.&lt;br /&gt;&lt;br /&gt;For the second case, if a class has a declared static member, because you cannot initialize it inside the class body (it belongs to the class, not the object), so if you forget defining this static member outside the body, the link error will also occur.&lt;br /&gt;&lt;br /&gt;The thrid one is the well-known fallacy: templates behave similarly as ordinary classes and functions with respect to the separation between their declarations and definitions. This is not true. The reason is that &lt;em&gt;a template&lt;/em&gt; actually is &lt;strong&gt;NOT &lt;/strong&gt;real code. A good anologic example is: the MS-Word has some letter templates, but they are not real letters until you fill them out. Therefore, one thing we need to remember: &lt;strong&gt;templated functions and classes don't actually exist until you use them&lt;/strong&gt;! A solution is: a header file including template declarations also constains their definitions. However, this seems to violate the rule of the separation of the declaration and definition.&lt;br /&gt;&lt;br /&gt;Reference:&lt;br /&gt;[1] &lt;a href="http://www.informit.com/guides/content.asp?g=cplusplus&amp;seqNum=298&amp;amp;rl=1"&gt;http://www.informit.com/guides/content.asp?g=cplusplus&amp;seqNum=298&amp;amp;rl=1&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-5402686776524966285?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/5402686776524966285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=5402686776524966285' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/5402686776524966285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/5402686776524966285'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/04/error-lnk2001-unresolved-external.html' title='Error LNK2001: unresolved external symbol...'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-2627152936301509606</id><published>2007-04-15T23:50:00.000-04:00</published><updated>2007-05-19T14:03:12.479-04:00</updated><title type='text'>Cooperative Diversity for Wireless Networks</title><content type='html'>Cooperative diversity can emmulate an antenna array and then exploit spatial diversity in wireless networks with fading channels. It exploits the broadcast nature of the wireless medium and allows radios to jointly transmit information through relaying.&lt;br /&gt;&lt;br /&gt;Traditionally, in ad hoc networks, packets are forwarded from the source to the destination through multi hops serially.  The well-known capacity of  wireless networks obtained by Gupta and Kumar in 2000 is with this strategy. By using Cooperative diversity, the source and the relay nodes may cooperate together for data transmission. The capacity of this kind of network has been investigated by Xie and Kumar.&lt;br /&gt;&lt;br /&gt;The use of cooperative diversity is manifold:&lt;br /&gt;1) Increase capacity (enlarge capacity region)&lt;br /&gt;2) Improve reliability in terms of diversity gain&lt;br /&gt;3) Diversity-multiplexing tradeoff&lt;br /&gt;&lt;br /&gt;Different algorithms can be applied for cooperative communication, some examples are:&lt;br /&gt;&lt;br /&gt;1) Amplify-and-Forward&lt;br /&gt;   In this case, relays just simply amplify the received signal with a linear transformation.&lt;br /&gt;2) Decode-and-Forward&lt;br /&gt;   Relays first detect and decode the received signals and then re-encode them. This decoding and re-encoding procedure can be considered as a non-linear transformation.&lt;br /&gt;3) Selection and dynamic relaying&lt;br /&gt;   In this case, cooperative terminals adapt their transmission format according to the measured channel state information.&lt;br /&gt;4) Incremental relaying&lt;br /&gt;   This scheme exploits limited feedback from the destination terminal for relaying.&lt;br /&gt;&lt;br /&gt;Incorporating  the cooperative diversity into the network is still an open problem.&lt;br /&gt;&lt;br /&gt;Reference:&lt;br /&gt;[1] J. Nicholas Laneman, "Cooperative diversity: models, algorithms and architectures," Cooperation in wireless networks, Springer, 2006&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-2627152936301509606?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/2627152936301509606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=2627152936301509606' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2627152936301509606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2627152936301509606'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/04/cooperative-diversity-for-wireless.html' title='Cooperative Diversity for Wireless Networks'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5786214393214651277.post-2731918823191496480</id><published>2007-04-11T11:30:00.000-04:00</published><updated>2007-04-11T16:45:42.970-04:00</updated><title type='text'>Adaptive modulation v.s. High order diversity</title><content type='html'>Today's learning:  adaptive modulation may become unnecessary as the diversity order is increased. It can be viewed as a lower-complexity alternative to diversity technologies, such as MIMO.&lt;br /&gt;&lt;br /&gt;Remember, adaptive modulation or diversity only offers advantages over fading channels. Adaptive modulation can employ high-order modulation schemes to adapt to the channel state and then increase the system throughput. Diversity utilizes the independent property between two or more links. When only one receiver is provided, adaptive modulation can be employed. But when more than two receivers are available, it is better to use diveristy technologies.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5786214393214651277-2731918823191496480?l=jinghaoxu.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jinghaoxu.blogspot.com/feeds/2731918823191496480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5786214393214651277&amp;postID=2731918823191496480' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2731918823191496480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5786214393214651277/posts/default/2731918823191496480'/><link rel='alternate' type='text/html' href='http://jinghaoxu.blogspot.com/2007/04/test.html' title='Adaptive modulation v.s. High order diversity'/><author><name>Jinghao Xu</name><uri>http://www.blogger.com/profile/04165659461747924669</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
