lab2-slides - CS 260 Computer Networks Lab 2 Peer-to-Peer...

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

View Full Document Right Arrow Icon
CS 260: Computer Networks Lab 2: Peer-to-Peer File Sharing
Background image of page 1

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

View Full DocumentRight Arrow Icon
Project Checkpoint Must be able to host a lobby Must be able to find hosts Must be able to join hosts Must be able to engage in text chat once joined Optional: Graceful handling of quitters Graceful handling of droppers Host can eject players
Background image of page 2
Lab 2: Peer-to-Peer File Sharing Discover LAN sessions using UDP broadcasts Use TCP to transfer streams of data “Host” and “Client” portions count for two different labs Download my executable so you can test either one Done today: 100% Place the code (lab-2.cpp only, including a report of several sentences as comments near the top of the file) in your submission folder Late submission: by 10am May 29, Tuesday Email me after your submission
Background image of page 3

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

View Full DocumentRight Arrow Icon
Session discovery Host listens for broadcasts Seekers send broadcast: “Is anyone hosting?” Typically done repeatedly Hosts respond directly with session info Seekers display found sessions to user Delete after no response for a period of time
Background image of page 4
Protocol Client broadcast: “I’m seeking, and my name is X” Server response: “I’m hosting file foo.txt (size yyyy), and my name is Z.” User chooses server Client opens TCP connection Client sends one byte: length of username Client sends username Server sends file
Background image of page 5

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

View Full DocumentRight Arrow Icon
Messages // Messages enum { MESSAGE_SEEKING, MESSAGE_HOSTING }; struct SMessage { char MessageMarker[ sizeof( MESSAGE_MARKER ) ]; BYTE MessageID; SMessage() { strcpy( MessageMarker, MESSAGE_MARKER ); } }; struct SMessageSeeking : public SMessage { SMessageSeeking() : SMessage() { MessageID = MESSAGE_SEEKING; } char strUsername[ MAX_USERNAME ]; }; struct SMessageHosting : public SMessage { SMessageHosting() : SMessage() { MessageID = MESSAGE_HOSTING; } char strUsername[ MAX_USERNAME ]; char strFileName[ MAX_PATH ]; DWORD dwFileSize; }; const DWORD MAX_MESSAGE = sizeof( SMessageHosting );
Background image of page 6
Hosts and Clients // Array of potential hosts struct SHost { UINT nID; SMessageHosting host; SOCKADDR_IN saFrom; DWORD dwReceivedTime; }; // Array of clients struct SClient { SOCKET s; SOCKADDR_IN sa; enum { STATE_RECEIVINGUSERNAMELEN, STATE_RECEIVINGUSERNAME, STATE_SENDING } state; DWORD dwPointer; CHAR strUsername[ MAX_USERNAME ]; BYTE nUsernameLen; };
Background image of page 7

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

View Full DocumentRight Arrow Icon
Hosting: Picking a file void HostMode( void ) { // List of connected clients std::vector< SClient > rgClients; // File path char strFilePath[ MAX_PATH ] = "\0"; // Retrieve our own HWND. Yes, this is a hack HWND hwndConsole = FindWindow( NULL, TITLE ); // Open a dialog to prompt for a file OPENFILENAME ofn = { 0 }; ofn.lStructSize = sizeof( ofn ); ofn.lpstrFile = strFilePath; ofn.nMaxFile = MAX_PATH; ofn.hwndOwner
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This lab report was uploaded on 04/18/2008 for the course CS 260 taught by Professor Hou during the Summer '07 term at DigiPen Institute of Technology.

Page1 / 27

lab2-slides - CS 260 Computer Networks Lab 2 Peer-to-Peer...

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

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