ECE 4110 – Internetwork Programming Client-Server Model.

Slides:



Advertisements
Similar presentations
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Advertisements

Programming with TCP – I
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
Sockets CS 3516 – Computer Networks. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Distributed Computing Systems Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Computer Networks Sockets.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Sockets IMGD Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Tutorial 8 Socket Programming
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
Computer Networks Sockets. Outline F Socket basics F Socket details.
Lecture 10 Overview. Network API Application Programming Interface – Services that provide the interface between application and protocol software often.
Operating Systems Sockets. Outline F Socket basics F TCP sockets F Socket details F Socket options F Final notes F Project 3.
CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007.
UNIX Sockets COS 461 Precept 1. Clients and Servers Client program – Running on end host – Requests service – E.g., Web browser Server program – Running.
UNIX Sockets COS 461 Precept 1.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
Ashutosh Shukla Lecture 3 Network Programming CS 640: Computer Networking.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
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.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Elementary TCP Sockets
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
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.
CS162B: IPv4 Socketing Jacob T. Chan. Socketing in the Real World  Most computer games are multiplayer in nature or have multiplayer components  DotA,
 Wind River Systems, Inc Chapter - 13 Network Programming.
---- IT Acumens. COM IT Acumens. COMIT Acumens. COM.
Ports Port - A 16-bit number that identifies the application process that receives an incoming message. Reserved ports or well-known ports (0 to 1023)
Remote Shell CS230 Project #4 Assigned : Due date :
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
Advanced Sockets API-II Vinayak Jagtap
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
Introduction to Socket
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Introduction to Sockets
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Review: – Why layer architecture? – peer entities – Protocol and service interface – Connection-oriented/connectionless service – Reliable/unreliable service.
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
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.
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level connection.Establishing.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
Sockets Intro to Network Programming. Before the internet... Early computers were entirely isolated No Internet No network No model No external communications.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Sockets API Developing Applications using the Sockets API.
Operating Systems Sockets ENCE 360.
UNIX Sockets COS 461 Precept 1.
Elementary UDP Sockets
Socket Programming in C
Transport layer API: Socket Programming
Socket Programming in C
TCP Sockets Programming
TCP/IP Socket Programming in C
Internet Networking recitation #8
Sockets.
Today’s topic: Basic TCP API
Presentation transcript:

ECE 4110 – Internetwork Programming Client-Server Model

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 2 References R. Stevens, “UNIX Network Programming,” Volume 1, 2 nd Edition R. Stevens, “TCP/IP Illustrated,” Volume 1 R. Stevens, “Advanced Programming in the UNIX Environment”

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 3 Introduction Example: The server process is the telnet daemon. The client processes are telnet clients. Typically, the server process runs with root permissions, and each client process runs with the permissions of the corresponding user. TCP/UDP and IP protocols are part of the kernel. Server Client #1 Client #2 Client #3

4 TCP Client-Server Model socket() connect() send() recv() close() socket() bind() listen() accept() recv() send() recv() close() process request blocks until connection from client connection establishment data (request) data (reply) end-of-file notification TCP Server TCP Client

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 5 Examples Under the directory /Stevens/unpv12e, libraries and source files written by R. Stevens are installed. Stevens defines wrapper functions for connect(), listen(), etc., to perform function call with error checking. The wrapper functions have the initial in upper-case. Under intro directory, you will find daytimetcpsrv.c and daytimetcpcli.c. Examine these two files. This example is similar to what you did in Lab 2.

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 6 TCP Socket Pair Each TCP connection is associated with a 4- tuple that defines the two ends of the connection: LocalIPAddress LocalTCPPort ForeignIPAddress ForeignTCPPort A socket pair uniquely identities every TCP connection on an internet. Same concept extends to UDP.

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 7 TCP Socket Programming Make sure the server is running and bound to the server port before client attempts to connect. Refer to manual pages and Unix Network Programming book for a thorough discussion of the following functions. We will discuss only the features relevant to us for the moment.

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 8 TCP Socket Programming (cont’d) socket() function: int socket(int domain, int type, int protocol); Returns a socket descriptor, sockfd, which is non-negative unless there is an error. domain: Specifies the protocol family. Possible values: AF_INET: IPv4 protocols (for TCP and UDP) type: Type of socket. Possible values: SOCK_STREAM: Stream socket (for TCP) SOCK_DGRAM: Datagram socket (for UDP) protocol: Particular protocol to be used with socket. Possible values: 0: for TCP and UDP

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 9 TCP Socket Programming (cont’d) bind() function: int bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); Returns 0 for success, -1 for error. sockfd: Socket descriptor returned by socket(). my_addr: Structure that contains information about local protocol- specific address. IPv4: my_addr is of type struct sockaddr_in rather than sockaddr. Therefore, a casting is required for my_addr. Set my_addr as follows: my_addr.sin_family = AF_INET; my_addr.sin_port = htons(port_no); my_addr.sin_addr.s_addr = htonl(INADDR_ANY); addrlen: Size of my_addr If port number is zero, kernel selects an ephemeral port.

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 10 TCP Socket Programming (cont’d) listen() function: int listen(int sockfd, int backlog); Converts unconnected socked into a passive socket, i.e., kernel should accept incoming connection requests. Returns 0 for success, -1 for error. sockfd: Socket descriptor returned by socket(). backlog: Maximum length the queue of pending connections may grow to. Possible value: 1

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 11 TCP Socket Programming (cont’d) accept() function: int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); Creates a new connected request when a request arrives at the listening socket sockfd. Returns the file descriptor for the new socket if successful, -1 for error. sockfd: Socket descriptor returned by socket(). addr: Address structure for the client. The exact structure of addr is determined by the socket’s family. addrlen: Length of the addr structure.

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 12 TCP Socket Programming (cont’d) connect() function: int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen); Returns 0 for success, -1 for error. sockfd: Socket descriptor returned by socket(). serv_addr: Structure that contains destination IP address and port number. Set serv_addr as follows: servaddr.sin_family = AF_INET; servaddr.sin_port = htons(port_no); inet_pton(AF_INET, server_ip_address, &servaddr.sin_addr); addrlen: Size of sockaddr

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 13 TCP Socket Programming (cont’d) close() function: int close(int sockfd); Closes sockfd and releases any locks. Do not access sockfd after close(). Returns 0 for success, -1 for error.

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 14 TCP Socket Programming (cont’d) recv() function: int recv(int sockfd, void *buf, size_t len, int flags); Returns the number of bytes received if successful, -1 for error. sockfd: Socket descriptor returned by socket(). buf: Buffer into which received data is written. len: Maximum number of bytes to be written to buf. flags: Multiple options OR’ed. Usually 0. Use MSG_DONTWAIT if you want non-blocking I/O. read() can also be used instead of recv().

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 15 TCP Socket Programming (cont’d) send() function: int send(int sockfd, const void *msg, size_t len, int flags); Returns the number of bytes sent if successful, -1 for error. sockfd: Socket descriptor returned by socket(). msg: Message that will be sent. len: Number of bytes to be sent. flags: Multiple options OR’ed. Usually 0. Use MSG_DONTWAIT if you want non-blocking I/O. write() can also be used instead of send().

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 16 TCP Socket Programming (cont’d) setsockopt(), getsockopt() functions: int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); Returns 0 for success, -1 for error. sockfd: Socket descriptor returned by socket(). level: Level at which the option resides. Possible value: IPPROTO_TCP optname: Option to be set. Possible value: TCP_NODELAY optval, optlen: Used to access option.

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 17 UDP Socket Programming UDP is connectionless. So, On the server side, listen() and accept() are not used. On the client side, connect() is not used typically. Instead of send() and recv(), use sendto() and recvfrom().

18 UDP Client-Server Model connect() sendto() recvfrom() close() socket() bind() recvfrom() sendto() process request blocks until datagram receiver from a client Only for connected UDP sockets data (reply) UDP Server UDP Client

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 19 UDP Socket Programming (cont’d) recvfrom() function: int recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); Same as recv(). In addition, from: Address structure for the source of the message. fromlen: Size of from. If from is NULL, same as recv().

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 20 UDP Socket Programming (cont’d) sendto() function: int send(int sockfd, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen); Same as send(). In addition, to: Address structure for the destination. tolen: Size of to.

Spring 2003 Tuna Tugcu ECE 4110 – Internetwork Programming 21 UDP Socket Programming (cont’d) UDP client may optionally use connect() to tell the kernel IP address and port number of destination. This is not a real connect operation. If connected UDP socket is being used, sendto() and recvfrom() cannot be used. Use send() and recv().