CSE 333 Section 8 - Client-Side Networking

Similar documents
Client-side Networking

CSE 333 SECTION 7. Client-Side Network Programming

CSE 333 SECTION 8. Sockets, Network Programming

CSE 333 SECTION 7. C++ Virtual Functions and Client-Side Network Programming

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks

CSE 333 SECTION 7. Client-Side Network Programming

CSE 333 SECTION 6. Networking and sockets

CSE 333 Section 3. Thursday 12 April Thursday, April 12, 12

Computer Network Programming

CSE 124 Discussion Section Sockets Programming 10/10/17

Outline. Option Types. Socket Options SWE 545. Socket Options. Out-of-Band Data. Advanced Socket. Many socket options are Boolean flags

IP Addresses, DNS. CSE 333 Spring Instructor: Justin Hsia

IP Addresses, DNS. CSE 333 Summer Teaching Assistants: Renshu Gu William Kim Soumya Vasisht

Introduction to Lab 2 and Socket Programming. -Vengatanathan Krishnamoorthi

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

The exam is closed book, closed notes, closed electronics, closed telepathy, open mind.

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions

Write your answer on the next page. You may remove this page for reference while working if you wish.

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets

Redesde Computadores(RCOMP)

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

UNIX System Programming Lecture 19: IP Sockets

CS 43: Computer Networks. 05: Socket Programming September 12-14, 2018

Sockets 15H2. Inshik Song

UNIX Sockets. COS 461 Precept 1

Systems software design NETWORK COMMUNICATIONS & RPC SYSTEMS

CSE 333 Lecture 16 - network programming intro

Socket Programming for TCP and UDP

Programming Internet with Socket API. Hui Chen, Ph.D. Dept. of Engineering & Computer Science Virginia State University Petersburg, VA 23806

Networked Applications: Sockets. End System: Computer on the Net

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron

TCP: Three-way handshake

UNIT IV- SOCKETS Part A

Review. Preview. Closing a TCP Connection. Closing a TCP Connection. Port Numbers 11/27/2017. Packet Exchange for TCP Connection

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013

A Socket Example. Haris Andrianakis & Angelos Stavrou George Mason University

Sockets and Parallel Computing. CS439: Principles of Computer Systems April 11, 2018

CSE 333 Final Exam June 6, Name ID #

CSCI 4061: Sockets and Network Programming

Tutorial on Socket Programming

Socket Programming TCP UDP

Computer Networks Prof. Ashok K. Agrawala

last time redo logging copy-on-write filesystems / snapshots distributed systems motivation, etc.

Networked Applications: Sockets. Goals of Todayʼs Lecture. End System: Computer on the ʻNet. Client-server paradigm End systems Clients and servers

Oral. Total. Dated Sign (2) (5) (3) (2)

Ports under 1024 are often considered special, and usually require special OS privileges to use.

Chapter 6. The Transport Layer. Transport Layer 3-1

EEC-484/584 Computer Networks

Outline. Distributed Computing Systems. Socket Basics (1 of 2) Socket Basics (2 of 2) 3/28/2014

STUDY OF SOCKET PROGRAMMING

Lecture 2. Outline. Layering and Protocols. Network Architecture. Layering and Protocols. Layering and Protocols. Chapter 1 - Foundation

Azblink API for Sending XMPP Messages via HTTP POST

Introduction to Computer Networks

CLIENT-SIDE PROGRAMMING

Network Communication

Elementary TCP Sockets

Group-A Assignment No. 6

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

CSE 333 SECTION 3. POSIX I/O Functions

Outline. Distributed Computer Systems. Socket Basics An end-point for a IP network connection. Ports. Sockets and the OS. Transport Layer.

Category: Informational J. Bound J. McCann Hewlett-Packard W. Stevens February 2003

Intended status: Standards Track. March 21, 2016

CSE 333 Lecture 8 - file and network I/O

Networks. Practical Investigation of TCP/IP Ports and Sockets. Gavin Cameron

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani

5. System Calls or Bust

Introduction to Socket Programming

목포해양대해양컴퓨터공학과. IPv6 적용

CSE 333 Final Exam March 16, Name ID #

CSE 333 Lecture network programming intro

CMPSC 311- Introduction to Systems Programming Module: Network Programming

Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현

Server-side Programming

Outline. Operating Systems. Socket Basics An end-point for a IP network connection. Ports. Network Communication. Sockets and the OS

The TCP Protocol Stack

// print product names in alphabetical order with total // number sold of each product using format name: total void PrintTotals();

2007 Microsoft Corporation. All rights reserved.

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Context. Distributed Systems: Sockets Programming. Alberto Bosio, Associate Professor UM Microelectronic Departement

Socket Programming. Sungkyunkwan University. Hyunseung Choo Copyright Networking Laboratory

Project 3. Reliable Data Transfer over UDP. NTU CSIE Computer Networks 2011 Spring

Client software design

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

#include <dirent.h> int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen); DIR *opendir(const char *name);

CS 640: Computer Networking

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

Socket Programming. Dr. -Ing. Abdalkarim Awad. Informatik 7 Rechnernetze und Kommunikationssysteme

Introduction to Socket Programming

Networks class. CS144 Introduction to Computer Networking. Administrivia. Administrivia 2. Grading. Labs. Goal: Teach the concepts underlying networks

6 장과제샘플코드 - 다자간채팅 (udp 버전 1) 목포해양대해양컴퓨터공학과

CSE/EE 461 Lecture 14. Connections. Last Time. This Time. We began on the Transport layer. Focus How do we send information reliably?

Hybrid of client-server and P2P. Pure P2P Architecture. App-layer Protocols. Communicating Processes. Transport Service Requirements

Communication. Sockets (Haviland Ch. 10)

CMPSC 311- Introduction to Systems Programming Module: Network Programming

Networks and Their Abstractions. CS439: Principles of Computer Systems April 9, 2018

CS321: Computer Networks Socket Programming

Transcription:

CSE 333 Section 8 - Client-Side Networking Welcome back to section! We re glad that you re here :) Networking Quick Review What are the following protocols used for? (bonus: what layer of the networking stack is it found?) DNS IP TCP UDP HTTP Why would you want to use TCP over UDP? Why would you want to use UDP over TCP?

For each of the following, identify the layer in the network stack that performs the described operation. Be sure you identify the layer, not the protocol. a). Use WiFi or Bluetooth to transmit data to other hosts. b). use media access control(mac) to figure out when and where to send the packet. c). Forward a packet from the local wired or wireless network to a different local network if its destination address is not on the same local network. d). If two packets that make up a message arrive out of order, rearrange them into the correct order before they are transmitted to the process reading the data. e). Send a 200 OK message to a web browser in reply to a request for something from a web server. f). Transmit an Ethernet packet on the local network from one host machine s NIC interface address to another s. g). Resolve what IP address is www.youtube.com pointing to. Step-by-step Client-Side Networking 1) Figure out what IP address and port to talk to. (getaddrinfo()) // returns 0 on success, negative number on failure int getaddrinfo(const char *hostname, // hostname to lookup const char *servname, // service name const struct addrinfo *hints, // desired output (optional) const addrinfo **res); // results structure

struct addrinfo { int ai_flags; // additional flags int ai_family; // AF_INET, AF_INET6, AF_UNSPEC int ai_socktype; // SOCK_STREAM, SOCK_DGRAM, 0 int ai_protocol; // IPPROTO_TCP, IPPROTO_UDP, 0 size_t ai_addrlen; // length of socket addr in bytes struct sockaddr* ai_addr; // pointer to socket addr char* ai_canonname; // canonical name struct addrinfo* ai_next; // can have linked list of records } 2) Create a socket. (socket()) // returns file descriptor on success, -1 on failure (errno set) int socket(int domain, // AF_INET, AF_INET6, etc. int type, // SOCK_STREAM, SOCK_DGRAM, etc. int protocol); // usually 0 3) Connect to the server. (connect()) // returns 0 on success, -1 on failure (errno set) int connect(int sockfd, // fd from step 2 struct sockaddr *serv_addr, // server info from step 1 int addrlen); // size of serv_addr 4) Transfer data through the socket. (read() and write()) // returns amount read, 0 for EOF, -1 on failure (errno set) ssize_t read(int fd, void *buf, size_t count); // returns amount written, -1 on failure (errno set) ssize_t write(int fd, void *buf, size_t count); Notice that these are the same POSIX calls you used for files! Remember you have to deal with partial reads/writes! 5) Close the socket when done. (close()) // returns 0 for success, -1 on failure (errno set) int close(int fd);

A bit of networking. When we were describing how a network server works, we listed 5 steps that need to be done to establish communication with a server, exchange data, and shut down. In the list below, fill in the name of the function that is used at each step, then give a 1-sentence description of the purpose of that step. 1. Function: Purpose: 2. Function: socket Purpose: Create a socket 3. Function: Purpose: 4. Function: read/write Purpose: 5. Function: Purpose: Write a program that reads a file (passed as the first argument to the program) and writes it in reverse to a server (hostname passed as the second argument, port passed as the third argument). int main (int argc, char **argv) { // Get the port from the arguments. // Get an appropriate sockaddr structure.

// Create a socket. // Connect to the remote host. // Iterate through the file and send to server. // Clean up. return EXIT_SUCCESS; }