Server-side Programming CSE 333 Autumn 2018

Slides:



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

Programming with TCP – I
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Socket Programming 0.
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.
Lecture 6 TCP Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Sockets Programming CS144 Review Session 1 April 4, 2008 Ben Nham.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
Tutorial 8 Socket Programming
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Sockets COS 518: Advanced Computer Systems Michael Freedman Fall
UNIX Sockets COS 461 Precept 1. Clients and Servers Client program – Running on end host – Requests service – E.g., Web browser Server program – Running.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
ECE 4110 – Internetwork Programming Client-Server Model.
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.
Assignment 3 A Client/Server Application: Chatroom.
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.
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.
Operating Systems Recitation 9, May 19-20, Iterative server Handle one connection request at a time. Connection requests stored in queue associated.
CS162B: IPv4 Socketing Jacob T. Chan. Socketing in the Real World  Most computer games are multiplayer in nature or have multiplayer components  DotA,
Remote Shell CS230 Project #4 Assigned : Due date :
Distributed Computing A Programmer’s Perspective.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Socket Programming Lab 1 1CS Computer Networks.
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.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Carnegie Mellon Proxy & Networking : Introduction to Computer Systems – Recitation H April 11, 2011.
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.
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.
CSE 333 – SECTION 8 Client-Side Network Programming.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
Assignment 3 A Client/Server Application: Chatroom
UNIX Sockets COS 461 Precept 1.
Week 13 - Friday CS222.
Socket Programming in C
Server-side Programming CSE 333 Spring 2018
Transport layer API: Socket Programming
Client-side Networking CSE 333 Spring 2018
Network Programming CSC- 341
UNIX Sockets Outline Homework #1 posted by end of day
Network Programming CSC- 341
UDP Sockets Programming
Socket Programming in C
TCP Sockets Programming
Advanced Network Programming spring 2007
Issues in Client/Server Programming
Chapter 2 Application Layer
Server-side Programming CSE 333 Summer 2018
Client-side Networking CSE 333 Summer 2018
Networking Introduction CSE 333 Autumn 2018
Client-side Networking CSE 333 Autumn 2018
C++ Constructor Insanity CSE 333 Autumn 2018
Concurrency: Processes CSE 333 Autumn 2018
Server-side Programming CSE 333 Winter 2019
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Client-side Networking CSE 333 Winter 2019
Internet Networking recitation #8
Today’s topic: Basic TCP API
Client-side Networking CSE 333 Spring 2019
Presentation transcript:

Server-side Programming CSE 333 Autumn 2018 Instructor: Hal Perkins Teaching Assistants: Tarkan Al-Kazily Renshu Gu Travis McGaha Harshita Neti Thai Pham Forrest Timour Soumya Vasisht Yifan Xu

Administrivia New exercise released today, due Wednesday morning Server-side programming hw4 out now – how’s it look?

Socket API: Server TCP Connection Pretty similar to clients, but with additional steps: Figure out the IP address and port on which to listen Create a socket bind() the socket to the address(es) and port Tell the socket to listen() for incoming clients accept() a client connection .read() and write() to that connection close() the socket Analogy: bakery/coffee shop/boba shop Steps 1-3: Morning prep work (still closed) Step 4: Open shop and let customers in (queue) Step 5: “Next customer in line, please!” Step 6: Transaction occurs Step 7: Customer leaves shop or store refuses service

Servers Servers can have multiple IP addresses (“multihoming”) Usually have at least one externally-visible IP address, as well as a local-only address (127.0.0.1) The goals of a server socket are different than a client socket Want to bind the socket to a particular port of one or more IP addresses of the server Want to allow multiple clients to connect to the same port Server reassigns client connections to different internal ports to differentiate https://en.wikipedia.org/wiki/Multihoming

Step 1: Figure out IP address(es) & Port Step 1: getaddrinfo() invocation may or may not be needed (but we’ll use it) Do you know your IP address(es) already? Static vs. dynamic IP address allocation Even if the machine has a static IP address, don’t wire it into the code – either look it up dynamically or use a configuration file Can request listen on all local IP addresses by passing NULL as hostname and setting AI_PASSIVE in hints.ai_flags Effect is to use address 0.0.0.0 (IPv4) or :: (IPv6)

Step 2: Create a Socket Step 2: socket() call is same as before Can directly use constants or fields from result of getaddrinfo() Recall that this just returns a file descriptor – IP address and port are not associated with socket yet

Step 3: Bind the socket Some specifics for addr: Looks nearly identical to connect()! Returns 0 on success, -1 on error Some specifics for addr: Address family: AF_INET or AF_INET6 What type of IP connections can we accept? POSIX systems can handle IPv4 clients via IPv6  Port: port in network byte order (htons() is handy) Address: specify particular IP address or any IP address “Wildcard address” – INADDR_ANY (IPv4), in6addr_any (IPv6) int bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen); http://man7.org/linux/man-pages/man2/bind.2.html in6addr_any is lowercase because it is a variable instead of a constant

Step 4: Listen for Incoming Clients Tells the OS that the socket is a listening socket that clients can connect to backlog: maximum length of connection queue Gets truncated, if necessary, to defined constant SOMAXCONN The OS will refuse new connections once queue is full until server accept()s them (removing them from the queue) Returns 0 on success, -1 on error Clients can start connecting to the socket as soon as listen() returns Server can’t use a connection until you accept() it int listen(int sockfd, int backlog); http://man7.org/linux/man-pages/man2/listen.2.html

Example #1 See server_bind_listen.cc Takes in a port number from the command line Opens a server socket, prints info, then listens for connections for 20 seconds Can connect to it using netcat (nc)

Step 5: Accept a Client Connection Returns an active, ready-to-use socket file descriptor connected to a client (or -1 on error) sockfd must have been created, bound, and listening Pulls a queued connection or waits for an incoming one addr and addrlen are output parameters *addrlen should initially be set to sizeof(*addr), gets overwritten with the size of the client address Address information of client is written into *addr Use inet_ntop() to get the client’s printable IP address Use getnameinfo() to do a reverse DNS lookup on the client int accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen);

Example #2 See server_accept_rw_close.cc Takes in a port number from the command line Opens a server socket, prints info, then listens for connections Can connect to it using netcat (nc) Accepts connections as they come Echoes any data the client sends to it on stdout and also sends it back to the client EAGAIN and EWOULDBLOCK checks are for when accept() is called on nonblocking sockets and there are no connections present to be accepted.

Something to Note Our server code is not concurrent Single thread of execution The thread blocks while waiting for the next connection The thread blocks waiting for the next message from the connection A crowd of clients is, by nature, concurrent While our server is handling the next client, all other clients are stuck waiting for it 

Extra Exercise #1 Write a program that: Creates a listening socket that accepts connections from clients Reads a line of text from the client Parses the line of text as a DNS name Does a DNS lookup on the name Writes back to the client the list of IP addresses associated with the DNS name Closes the connection to the client