Programming Project II CS475 Randall

advertisement
Programming Project II
CS475
Randall
DUE Oct 9, 2015
For Programming Project II you will be writing a weather server/client application. The weather
information will be taken from weather.yahooapis.com.
Weather information can be received from this website by adding:
/forecastrss?w=2502265 to the URL.
2502265 is the location code for the place that you would like to receive weather
information. Other codes can be found by going to weather.yahoo.com and searching for a
city or place. If you look in the URL after the search you will find the location code
for the city or place.
Examples:
Evansville: 2400767
Indianapolis: 2427032
St. Louis: 2486982
When you make a request the html response will be XML code that is the weather
information for your request.
Example for Evansville Indiana:
<rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.or
g/2003/01/geo/wgs84_pos#" version="2.0">
<channel>
<title>Yahoo! Weather - Evansville, IN</title>
<link>
http://us.rd.yahoo.com/dailynews/rss/weather/Evansville__IN/*http://weather.yahoo.com/for
ecast/USIN0190_f.html
</link>
<description>Yahoo! Weather for Evansville, IN</description>
<language>en-us</language>
<lastBuildDate>Fri, 19 Sep 2014 7:52 am CDT</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Evansville" region="IN" country="United States"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="58" direction="60" speed="6"/>
<yweather:atmosphere humidity="78" visibility="10" pressure="30.12" rising="1"/>
<yweather:astronomy sunrise="6:33 am" sunset="6:51 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>
http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif
</url>
</image>
<item>
<title>Conditions for Evansville, IN at 7:52 am CDT</title>
<geo:lat>37.98</geo:lat>
<geo:long>-87.56</geo:long>
<link>
http://us.rd.yahoo.com/dailynews/rss/weather/Evansville__IN/*http://weather.yahoo.com/for
ecast/USIN0190_f.html
</link>
<pubDate>Fri, 19 Sep 2014 7:52 am CDT</pubDate>
<yweather:condition text="Fair" code="34" temp="58" date="Fri, 19 Sep 2014 7:52 am CDT"/>
<description>
<![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/34.gif"/><br /> <b>Current Conditions:</b><br />
Fair, 58 F<BR /> <BR /><b>Forecast:</b><BR /> Fri - Sunny. High: 80 Low: 60<br /> Sat Partly Cloudy. High: 85 Low: 68<br /> Sun - Partly Cloudy. High: 80 Low: 52<br /> Mon Sunny. High: 75 Low: 49<br /> Tue - Sunny. High: 77 Low: 51<br /> <br /> <a
href="http://us.rd.yahoo.com/dailynews/rss/weather/Evansville__IN/*http://weather.yahoo.c
om/forecast/USIN0190_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/> (provided by
<a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]>
</description>
<yweather:forecast day="Fri" date="19 Sep
2014" low="60" high="80" text="Sunny" code="32"/>
<yweather:forecast day="Sat" date="20 Sep 2014" low="68" high="85" text="Partly
Cloudy" code="30"/>
<yweather:forecast day="Sun" date="21 Sep 2014" low="52" high="80" text="Partly
Cloudy" code="30"/>
<yweather:forecast day="Mon" date="22 Sep
2014" low="49" high="75" text="Sunny" code="32"/>
<yweather:forecast day="Tue" date="23 Sep
2014" low="51" high="77" text="Sunny" code="32"/>
<guid isPermaLink="false">USIN0190_2014_09_23_7_00_CDT</guid>
</item>
</channel>
</rss>
<!-fan1652.sports.bf1.yahoo.com Fri Sep 19 06:25:12 PDT 2014
-->
Your Server Program should allow a client application to make a request to receive
weather data from at least 3 different cities. You can provide as much information as
you would like but you must include the current conditions and 5 day forcast.
To start your client application it should take 2 arguments the server name, and server
port number. Your client application should use gethostbyname to resolve the server IP.
Your Client application should provide a text based menu that will provide the user a
list of available cities. The User should be prompted to make a selection, Once the
selection has been made the client should contact your server to retrieve the current
weather data for the city selected. The Client should then disconnect from the server.
The client should then present the current weather data in a clear form to the user. At
this point the user should be asked if they would like to check the weather of another
city or exit.
Making the html request from c++ is simple.
You will be connected to the yahoo server just like you have connected to any
other server, but you will connect via port 80. Once you are connected you will perform
a Get command on the server which will return the XML code to your program you will need
to programmatically retrieve the data and parse out the information that you need.
Get: The following 2 lines of code request the data from the weather server once a socket
has been created with the server. The first argument “weather” below is the socket
descriptor that was created with the server.
send(weather, "GET /forecastrss?w=2502265 HTTP/1.1\n", strlen("GET /forecastrss?w=2502265
HTTP/1.1\n"), 0);
send(weather, "host: weather.yahooapis.com\n\n", strlen("host: weather.yahooapis.com\n\n"), 0);
The final portion of project 2 will be to write an application protocol for your
application. The Protocol should explain data transfer, and the client/server
relationship.
Download