snowcast - CS168 Programming Assignment 1: Snowcast...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS168 Programming Assignment 1: Snowcast Assignment Out: January 28, 2010 Milestone: February 5, 2010, 6pm Assignment Due: February 12, 2010, 4pm 1 Introduction You will be implementing a simple Internet Radio Station. The purpose of this assignment is to become familiar with sockets and threads, and to get you used to thinking about network protocols. If youre unfamiliar with sockets or threads, you should read the pages about them linked from the course webpage. As always, e-mail us at or to come to one of our office hours if you have further questions. 2 Protocol This assignment has two parts: the server, which streams songs, and a pair of clients for connecting to the server and receiving songs. There are two kinds of data being sent between the server and the client. One is the control data. The client uses this data to specify which station to listen to and the server uses it to give the client song information. The other kind is the song data, which the server reads from song files and streams to the client. You will be using TCP for the control data and UDP for the song data. 2.1 Client to Server Commands The client sends the server commands . There are two commands the client can send the server, in the following format. Hello: uint8_t commandType = 0; uint16_t udpPort; SetStation: uint8_t commandType = 1; uint16_t stationNumber; A uint8_t 1 is an unsigned 8-bit integer. A uint16_t is an unsigned 16-bit integer. Your programs should use network byte order . 2 So, to send a Hello command, your client must send exactly three bytes to the server. 1 You can use these types from C if you #include <inttypes.h> . 2 Use the functions htons , htonl , ntohs and ntohl to convert from network to host byte order and back. 1 CS168 Snowcast The Hello command is sent when the client connects to the server. It tells the server what UDP port the server should be streaming song data to. The SetStation command is sent to pick an inital station or to change stations. stationNumber identifies the station. 2.2 Server to Client Replies There are three possible replies the server may send to the client: Welcome: uint8_t replyType = 0; uint16_t numStations; Announce: uint8_t replyType = 1; uint8_t songnameSize; char songname[songnameSize]; InvalidCommand: uint8_t replyType = 2; uint8_t replyStringSize; char replyString[replyStringSize]; A Welcome reply is sent in response to a Hello command. Stations are numbered sequentially from 0, so a numStations of 30 means 0 through 29 are valid. A Hello command, followed by a Welcome reply, is called a handshake . An Announce reply is sent on two occasions: after a client sends a SetStation command, or when the station a client is listening to changes its song. songnameSize represents the length, in bytes, of the filename, while songname contains the filename itself. The string must be formatted in ASCII and must not be null-terminated . So, to announce a song called Beat It , your client must send the...
View Full Document

This note was uploaded on 12/03/2010 for the course CS 168 taught by Professor Jj during the Spring '10 term at Brown.

Page1 / 8

snowcast - CS168 Programming Assignment 1: Snowcast...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online