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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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 );
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; };
Image of page 7

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

View Full Document Right 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 );
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern