Lab tutorial Lab assignment 2 Fall 2006

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
Review: –What functionality is supported by IP? –What IP does not do? –How many classes of IP addresses? –Explain fields in an IP header? –How subnet works?
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
UDP and Multi-thread Socket Programming
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Client 1 Client 2 Server Child Process1 Child Process2 (1) (2) (3) serverbase.txt Note: each child process keeps a separate copy of the DB.
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
2: Application Layer 1 Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5th edition. Jim Kurose, Keith Ross Addison-Wesley, April.
1 CCNA 2 v3.1 Module Intermediate TCP/IP CCNA 2 Module 10.
TCP. Learning objectives Reliable Transport in TCP TCP flow and Congestion Control.
Lecture 8 UDP Sockets & I/O Multiplexing
Project 2: A P2P Chat Application Review Ananth Rao.
Process-to-Process Delivery:
TRANSPORT LAYER T.Najah Al-Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System NET331.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Socket Programming References: redKlyde ’ s tutorial set Winsock2 for games (gamedev.net)
CS1652 September 13th, 2012 The slides are adapted from the publisher’s material All material copyright J.F Kurose and K.W. Ross, All Rights.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
University of Calgary – CPSC 441.  UDP stands for User Datagram Protocol.  A protocol for the Transport Layer in the protocol Stack.  Alternative to.
Network Services Networking for Home & Small Business.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.
Sockets API Overview Sockets with UDP Sockets with TCP Fast Sockets (Fast UDP) IP Multicasting.
Transport Layer Moving Segments. Transport Layer Protocols Provide a logical communication link between processes running on different hosts as if directly.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
1 COMP445 Fall 2006 Lab assignment 1. 2 STEP1: Get the name of the second party STEP2: Get phone number from white pages CALLERRECEIVER STEP1: Plug the.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Introduction to Socket
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Client/Server Socket Programming Project
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
Socket Programming.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
Today’s topic: UDP Reliable communication over UDP.
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
EECS340 Recitation 1: Very helpful to your project Hongyu Gao 1.
1 Computer Communication & Networks Lecture 23 & 24 Transport Layer: UDP and TCP Waleed Ejaz
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
1 UDP Sockets Programming Creating UDP sockets.Creating UDP sockets. –Client –Server Sending data.Sending data. Receiving data.Receiving data. Connected.
SOCKET PROGRAMMING Presented By : Divya Sharma.
CS 1652 Jack Lange University of Pittsburgh
Review: TCP Client-Server Interaction
Imam Ahmad Trinugroho, ST., MMSI
Transport Layer Our goals:
Transport layer API: Socket Programming
Network Programming CSC- 341
UNIX Sockets Outline Homework #1 posted by end of day
UDP Sockets Programming
Socket Programming.
CSC Advanced Unix Programming, Fall 2015
Chapter 06. UDP Server/Client.
Socket Programming(1/2)
Socket Programming with UDP
Presentation transcript:

Lab tutorial Lab assignment 2 Fall 2006 ae_abdal@cs.concordia.ca COMP 445 Lab tutorial Lab assignment 2 Fall 2006 ae_abdal@cs.concordia.ca

Lab 2 Specification Transfer files using UDP. Packets might be lost during the transfer. (router.cpp code drops packets) Output of program is the same as Lab1. There are couple of new concepts: Stop and Wait protocol: to guarantee delivery Three way handshake: to start the S/W protocol.

Lab 1 server Client TCP guarantees that all packets are delivered.

Stop and wait server Client If a packet is dropped, the server will not know

Stop and wait server Client packet Ack packet Ack packet Ack Client waits for an Ack for every packet

Stop and wait server Client packet Ack Wait for an ack. Packet LOST After a timeout, send the same packet again Packet LOST packet Ack Client waits for an Ack for every packet

Stop and wait server Client Packet Ack Wait for an ack. Packet After a timeout, send the same packet again Packet Ack LOST Packet Ack How will the server know that the third packet is the same as the second packet.

Stop and wait server Client Packet1 Ack1 Wait for an ack. Packet2 After a timeout, send the same packet again Packet2 Ack2 LOST Packet2 After checking the number, the client ignore this packet Ack2 How will the server know that the third packet is the same as the second packet. Solution: number the packets

Stop and wait numbering system server Client Packet0 Ack0 Wait for an ack. After a timeout, send the same packet again Packet1 Ack1 LOST Packet1 Client expects packet0, when packet1 is received, it ignores it. Ack1 How will the server know that the third packet is the same as the second packet. Solution: number the packets

Three way hand shake To fix the starting numbers at the source and destination, its good idea to add some hand shake above all this process.

Three way hand shake Client server 36 55 Client server 36 Client generates random number let it be equal to 36 The server save this number, and generate its own number 55. 36, 55 36 55 55 36 55

send 36 36 55 Client server 36 Client generates random number let it be equal to 36 The server save this number, and generate its own number 55. 36, 55 36 55 55 36 55 1 packet1 ack1

receive 36 36 55 Client server 36 Client generates random number let it be equal to 36 The server save this number, and generate its own number 55. 36, 55 36 55 55 36 55 packet0 1 ack0

Program architecture Server Client Router discard delay port 5001 port 7000 | port 7001 Router discard delay

Main differences - socket Creating a UDP socket Instead of: s = socket(AF_INET,SOCK_STREAM,0) Use: s = socket(AF_INET,SOCK_DGRAM,0) Binding: Client: binds its socket with a physical address (IP : INADDR_ANY and port number : 5000) Server: binds its socket with a physical address (IP : INADDR_ANY and port number : 5001)

SOCKADDR_IN sa; // port 5000, client IP address SOCKET s; SOCKADDR_IN sa; // port 5000, client IP address SOCKADDR_IN sa_in; // router info, IP, port(7000) if((s = socket(AF_INET,SOCK_DGRAM,0))==INVALID_SOCKET) throw "Socket failed\n"; memset(&sa,0,sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons(port); sa.sin_addr.s_addr = htonl(INADDR_ANY); //host to network //bind the port to the socket if (bind(s,(LPSOCKADDR)&sa,sizeof(sa)) == SOCKET_ERROR) throw "can't bind the socket"; cin >> remotehost; rp=gethostbyname(remotehost); memset(&sa_in,0,sizeof(sa_in)); memcpy(&sa_in.sin_addr, rp->h_addr, rp->h_length); sa_in.sin_family = rp->h_addrtype; sa_in.sin_port = htons(7000);

SOCKADDR_IN sa; // port 5001, server IP address SOCKET s; SOCKADDR_IN sa; // port 5001, server IP address SOCKADDR_IN sa_in; // router info, IP, port(7001) if((s = socket(AF_INET,SOCK_DGRAM,0))==INVALID_SOCKET) throw "Socket failed\n"; memset(&sa,0,sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons(port); sa.sin_addr.s_addr = htonl(INADDR_ANY); //bind the port to the socket if (bind(s,(LPSOCKADDR)&sa,sizeof(sa)) == SOCKET_ERROR) throw "can't bind the socket"; router IP and port numbers are obtained from the recvfrom(…) function.

Main differences - sending Sending frames – you pass the destination address to the send() function. Instead of: ibytessent = send(s, (char*)&message_frame, sizeof(message_frame), 0); Use: ibytessent = sendto(s, (const char*)&message_frame, sizeof(message_frame), 0,(struct sockaddr*) &sa_in, sizeof(sa_in));

Main differences - receiving Receiving frames (you receive the socket address of the sender) Instead of: ibytesrecv = recv(s, (char*)& message_frame, sizeof(message_frame),0) Use: fd_set readfds; //fd_set is a type FD_ZERO(&readfds); //initialize FD_SET(s, &readfds); //put the socket in the set if(!(outfds = select (1 , &readfds, NULL, NULL, & timeouts))) {//timed out, return} if (outfds == 1) //receive frame ibytesrecv = recvfrom(s, (char*)& message_frame, sizeof(message_frame),0, (struct sockaddr*)&fromAddr, &fromAddrSize); If this parameter is NULL, you are listening forever Readfds = file descriptor set for readable sockets

How to define a timer with 300ms for select? #define UTIMER 300000 #define STIMER 0 struct timeval timeouts; timeouts.tv_sec=STIMER; timeouts.tv_usec=UTIMER; Readfds = file descriptor set for readable sockets

Stop and wait protocol Client Send a packet if time_out send the packet again else //ack received send a new packet

Stop and wait protocol Server wait for the first packet send acknowledge while(!EOF) Get a packet; Send an ack;

Packet structure used #define STOPNWAIT 1 //Bits width For stop and wait struct MESSAGE_FRAME { unsigned char header; unsign int snwseq:STOPNWAIT; char data[MAX_SIZE];//or error message } message_frame; struct THREE_WAY_HS{ int client_number; int server_number; int direction; char file_name[FILE_NAME_SIZE]; } three_way_hs;

Three way hand-shaking #include <stdlib.h> THREE_WAY_HS three_way_hs; srand((unsigned)time(NULL)); CLIENT SERVER three_way_hs.client_number = rand(); You may send the file name and the direction here three_way_hs.server_number = rand(); sequence_number = three_way_hs.server_number % 2; Send an acknowledgment with sequence_number

”Socket error 10054” If the client sends out its first packet, the router has received it and forwarded it to the server side. Then the Router displays an error”Socket error 10054” and the server seems to receive nothing. What’s wrong with my program? check your receiving code of the server side, make sure you did every thing right(e.g when you are binding the server socket, you give the right port number to the server socket address)