1 Carnegie Mellon Proxylab and stuff 15-213: Introduction to Computer Systems Recitation 13: November 19, 2012 Donald Huang (donaldh) Section M.

Slides:



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

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?
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.
1 Carnegie Mellon Networking Basics and Concurrent Programming Shiva (sshankar) Section M.
Tutorial 8 Socket Programming
Fork Fork is used to create a child process. Most network servers under Unix are written this way Concurrent server: parent accepts the connection, forks.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Introduction to Project 1 Web Client and Server Jan 2006.
Lecture 10 Overview. Network API Application Programming Interface – Services that provide the interface between application and protocol software often.
CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007.
Carnegie Mellon 1 Proxy Web & Concurrency Rohith Jagannathan April 13 th, /18-213: Introduction to Computer Systems Recitation 13.
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.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
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.
Elementary TCP Sockets
Zhu Reference: Daniel Spangenberger Computer Networks, Fall 2007 PPT-4 Socket Programming.
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,
---- IT Acumens. COM IT Acumens. COMIT Acumens. COM.
Remote Shell CS230 Project #4 Assigned : Due date :
1 Concurrent Programming. 2 Outline Concurrent programming –Processes –Threads Suggested reading: –12.1, 12.3.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Introduction to Socket
Week 16 (April 25 th ) Outline Thread Synchronization Lab 7: part 2 & 3 TA evaluation form Reminders Lab 7: due this Thursday Final review session Final.
Socket Programming Lab 1 1CS Computer Networks.
Carnegie Mellon 1 Proxy Recitation Jeffrey Liu Recitation 13: November 23, 2015.
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.
回到第一頁 Client/sever model n Client asks (request) – server provides (response) n Typically: single server - multiple clients n The server does not need.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Thread S04, Recitation, Section A Thread Memory Model Thread Interfaces (System Calls) Thread Safety (Pitfalls of Using Thread) Racing Semaphore.
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.
Carnegie Mellon Recitation 11: ProxyLab Fall 2009 November 16, 2009 Including Material from Previous Semesters' Recitations.
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
CS 3700 Networks and Distributed Systems
Threads Synchronization Thread-safety of Library Functions
Concurrent Programming November 13, 2008
Socket Programming in C
Tutorial on Socket Programming
CS 3700 Networks and Distributed Systems
Concurrent Servers Topics Limitations of iterative servers
Client-side Networking CSE 333 Spring 2018
Socket Programming in C
Recitation 9 Greg Reshko
TCP Sockets Programming
Advanced Network Programming spring 2007
Client-side Networking CSE 333 Summer 2018
Concurrent Programming November 13, 2008
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Sockets.
Today’s topic: Basic TCP API
Presentation transcript:

1 Carnegie Mellon Proxylab and stuff : Introduction to Computer Systems Recitation 13: November 19, 2012 Donald Huang (donaldh) Section M

2 Carnegie Mellon Topics Summary of malloclab News Sockets Threads Proxylab

3 Carnegie Mellon Malloclab review Questions, comments, lessons learned? Starting simple and making improvements is a good way to write code  Nice because you can have something simple working relatively easily  You can test each new optimization alone When you write your code, write it so that it can be easily maintained/changed  “how can I write my explicit list so that I can change it to seglists later?”

4 Carnegie Mellon Topics Summary of malloclab News Sockets Threads Proxylab

5 Carnegie Mellon News Last day to turn in malloc is today (if using two late days and taking a late penalty) Proxylab was out last Friday

6 Carnegie Mellon Topics Summary of malloclab News Sockets Threads Proxylab

7 Carnegie Mellon Sockets To get a struct hostent for a domain name:  struct hostent * gethostbyname(const char *name);  not threadsafe, threadsafe version is gethostbyname_r What is a socket?  To an application, a socket is a file descriptor that lets the application read/write from/to the network  (all Unix I/O devices, including networks, are modeled as files) Clients and servers communicate with each other by reading from and writing to socket descriptors The main difference between regular file I/O and socket I/O is how the application “opens” the socket descriptors

Sockets API int socket(int domain, int type, int protocol); int bind(int socket, const struct sockaddr *address, socklen_t address_len); int listen(int socket, int backlog); int accept(int socket, struct sockaddr *address, socklen_t *address_len); int connect(int socket, struct sockaddr *address, socklen_t address_len); int close(int fd); ssize_t read(int fd, void *buf, size_t nbyte); ssize_t write(int fd, void *buf, size_t nbyte); 8 Carnegie Mellon

Sockets API int socket(int domain, int type, int protocol);  used by both clients and servers  int sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);  Create a file descriptor for network communication  One socket can be used for two-way communication 9 Carnegie Mellon

Sockets API int bind(int socket, const struct sockaddr *address, socklen_t address_len);  used by servers  struct sockaddr_in sockaddr; memset(&sockaddr, 0, sizeof(sockaddr); sockaddr.sin_family = AF_INET; sockaddr.sin_addr.s_addr = INADDR_ANY; sockaddr.sin_port = htons(listenPort) err = bind(sock_fd, (struct sockaddr *) sockaddr, sizeof(sockaddr));  sock_fd: file descriptor of socket  my_addr: address to bind to, and information about it, like the port  addrlen: size of addr struct  Associate a socket with an IP address and port number 10 Carnegie Mellon

Sockets API int listen(int socket, int backlog);  used by servers  err = listen(sock_fd, MAX_WAITING_CONNECTIONS);  socket: socket to listen on  backlog: maximum number of waiting connections int accept(int socket, struct sockaddr *address, socklen_t *address_len);  used by servers  struct sockaddr_in client_addr; socklen_t my_addr_len = sizeof(client_addr); client_fd = accept(listener_fd, &client_addr, &my_addr_len);  socket: socket to listen on  address: pointer to sockaddr struct to hold client information after accept returns  return: file descriptor 11 Carnegie Mellon

Sockets API int connect(int socket, struct sockaddr *address, socklen_t address_len);  used by clients  attempt to connect to the specified IP address and port described in address int close(int fd);  used by both clients and servers  (also used for file I/O)  fd: socket fd to close 12 Carnegie Mellon

Sockets API ssize_t read(int fd, void *buf, size_t nbyte);  used by both clients and servers  (also used for file I/O)  fd: (socket) fd to read from  buf: buffer to read into  nbytes: buf length ssize_t write(int fd, void *buf, size_t nbyte);  used by both clients and servers  (also used for file I/O)  fd: (socket) fd to write to  buf: buffer to write  nbytes: buf length 13 Carnegie Mellon

14 Carnegie Mellon

15 Carnegie Mellon Topics Summary of malloclab News Sockets Threads Proxylab

16 Carnegie Mellon Threads Similarities to processes  each thread has its own logical control flow (its own registers, so its own eip and stuff)  multiple threads can be in the middle of running at the same time, possibly on different cores  the kernel decides when to context switch to and from a thread (or a thread can voluntarily give up its share of cpu time by calling sleep, pause, sigsuspend, or something similar) Differences with processes  threads share code and data; processes generally don’t  threads are less expensive to make than processes (processes are about 2x more expensive to create and reap)

17 Carnegie Mellon Threads Each thread has its own stack/registers, including stack pointer and program counter (imagine what would happen otherwise) Processes start out as having one thread, and they also have code, data, page directory/table, file descriptors, and some other things associated with them

18 Carnegie Mellon Threads: pthreads interface Creating/reaping threads  pthread_create  pthread_join To get your thread ID  pthread_self Terminating threads  pthread_cancel  pthread_exit synchronizing access to shared variables  pthread_mutex_init  pthread_mutex_[un]lock  pthread_rwlock_init  pthread_rwlock_[wr]rdlock

19 Carnegie Mellon Threads A thread terminates implicitly when its top-level thread routine returns A thread terminates explicitly by calling pthread_exit(NULL) pthread_exit(NULL) only terminates the current thread, NOT the process exit(0) terminates ALL the threads in the process (meaning the whole process terminates pthread_cancel(tid) terminates the thread with id equal to tid

20 Carnegie Mellon Threads Joinable threads can be reaped and killed by other threads  must be reaped with pthread_join to free memory and resources Detached threads cannot be reaped or killed by other threads  resources are automatically reaped on termination Default state is joinable  use pthread_detach(pthread_self()) to make detached

21 Carnegie Mellon Multithreaded Hello World

22 Carnegie Mellon Topics Summary of malloclab News Sockets Threads Proxylab

Proxylab: what a proxy is?? intermediary between client and server 23 Carnegie Mellon

Proxylab write a web proxy  multi-threaded  caching should work for most sites (not https connections though)  cnn.com  google.com  youtube.com  (not facebook.com) Forwards requests from the client to the server  acts as a server to the client, but as a client to the server the client is asking you to read from 24 Carnegie Mellon

Proxylab: recommended progress implement a sequential proxy  this proxy will be very slow in loading webpages upgrade to multithreaded proxy  should be decently fast add caching  this involves some multithreading issues we’ll talk about solving next week You are not given any tests, so make sure you test your proxy well on your own! 25 Carnegie Mellon

26 Carnegie Mellon Questions? (sockets, proxylab, what a proxy is??) (come to office hours if you need help)