1 Netcomm 2005 - Sockets Communication Networks Recitation 1.

Slides:



Advertisements
Similar presentations
Socket Programming CS3320 Fall 2010.
Advertisements

Sockets: Network IPC Internet Socket UNIX Domain Socket.
Jieun Song Port-Binding & Connect-Back Shellcode.
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles m We will look at using sockets in C.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
1 Netcomm Recitation 1: Sockets Communication Networks Recitation 1.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Tutorial 8 Socket Programming
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Introduction to Socket Programming April What is a socket? An interface between application and network –The application creates a socket –The socket.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
ISP – 9 th Recitation Socket programming – Client side.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
Socket Programming Based on tutorial prepared by EUISOK CHUNG CS3320 Spring2008.
CPSC 441 TUTORIAL – JANUARY 18, 2012 TA: MARYAM ELAHI INTRODUCTION TO SOCKET PROGRAMMING WITH C.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Operating Systems Chapter 9 Distributed Communication.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Sirak Kaewjamnong Computer Network Systems
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.
 Wind River Systems, Inc Chapter - 13 Network Programming.
1 Writing Network Applications using the TCP/IP Protocol Stack: Socket Programming.
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles m We will look at using sockets in C.
CS x760 Computer Networks1 Socket Programming. CS 6760 Computer Networks2 Socket Programming  What is a socket?  Using sockets  Types (Protocols) ‏
Remote Shell CS230 Project #4 Assigned : Due date :
Computer Networks : TP1 Prof. Dr. Amine Berqia and Prof. Dr. Fernando Lobo {bamine,
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles m We will look at using sockets in C.
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles m We will look at using sockets in C.
1 Introduction to Computer Networks Ilam University By: Dr. Mozafar Bag Mohammadi Sockets.
The Pocket Guide to TCP/IP Sockets: C Version Michael J. Donahoo Kenneth L. Calvert.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
UNIT8: SOCKETS Topics Introduction to sockets Socket Addresses
University of Calgary – CPSC 441.  A socket is an interface between the application and the network (the lower levels of the protocol stack)  The application.
Introduction to Socket
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles m We will look at using sockets in C m Note:
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,
Network Programming Berkeley Sockets (BSD)
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
CPSC Application Layer 1 Trying out HTTP (client side) for yourself 1. Telnet to your favorite Web server: Opens TCP connection to port 80 (default.
Lecture 15 Socket Programming 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.
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.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Socket Programming What is a socket? Using sockets Types (Protocols)
CSCE 313 Network Socket MP8 DUE: FRI MAY 5, 2017
Socket Programming in C
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Introduction to Computer Networks
Transport layer API: Socket Programming
Socket Programming What is a socket? Using sockets Types (Protocols)
Socket Programming What is a socket? Using sockets Types (Protocols)
Socket Programming What is a socket? Using sockets Types (Protocols)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Socket Programming What is a socket? Using sockets Types (Protocols)
Sockets.
CSI 4118 – UNIVERSITY OF OTTAWA
Presentation transcript:

1 Netcomm Sockets Communication Networks Recitation 1

2 Netcomm Sockets Administrative Nir AndelmanNir Andelman –Open Space, (640)7438 – –website: omnet05/netcom.html omnet05/netcom.html omnet05/netcom.html –Grader: TBD

3 Netcomm Sockets TCP/IP Socket Programming

4 Netcomm Sockets What is a socket? An interface between application and the networkAn interface between application and the network The application can send/receive data to/from the network -- communicateThe application can send/receive data to/from the network -- communicate Application Network API Protocol A Protocol B Protocol C

5 Netcomm Sockets A Socket-eye view of the Internet Each host machine has an IP addressEach host machine has an IP address medellin.cs.columbia.edu ( ) cluster.cs.columbia.edu ( , , , ) newworld.cs.umass.edu ( )

6 Netcomm Sockets Ports Port 0 Port 1 Port Each host has 65,536 portsEach host has 65,536 ports Some ports are reserved for specific appsSome ports are reserved for specific apps –20,21: FTP –23: Telnet –80: HTTP r A socket provides an interface to address IP:port pair

7 Netcomm Sockets Functions needed: Specify local and remote communication endpointsSpecify local and remote communication endpoints Initiate a connectionInitiate a connection Send and receive dataSend and receive data Terminate a connectionTerminate a connection

8 Netcomm Sockets Socket Creation in C: socket() int s = socket(domain, type, protocol);int s = socket(domain, type, protocol); –s: socket descriptor (an integer (like a file-handle) –domain: integer, communication domain e.g., PF_INET (IPv4 protocol) – typically usede.g., PF_INET (IPv4 protocol) – typically used –type: communication type SOCK_STREAM: reliable, 2-way, connection-based serviceSOCK_STREAM: reliable, 2-way, connection-based service SOCK_DGRAM: unreliable, connectionless,SOCK_DGRAM: unreliable, connectionless, –protocol: specifies protocol (see file /etc/protocols for a list of options) - usually set to 0

9 Netcomm Sockets Socket Descriptor Data Structure Descriptor Table Family: PF_INET Service: SOCK_STREAM Local IP: Remote IP: Local Port: 2249 Remote Port: 3726 Family: PF_INET Service: SOCK_STREAM Local IP: Remote IP: Local Port: 2249 Remote Port: 3726

10 Netcomm Sockets Two essential types of sockets SOCK_STREAMSOCK_STREAM –a.k.a. TCP –reliable delivery –in-order guaranteed –connection-oriented –bidirectional SOCK_DGRAMSOCK_DGRAM –a.k.a. UDP –unreliable delivery –no order guarantees –no notion of “connection” –can send or receive App socket Dest. App socket D1 D3 D2

11 Netcomm Sockets The bind() function associates and (can exclusively) reserves a port for use by the socketassociates and (can exclusively) reserves a port for use by the socket int status = bind(sockid, &addrport, size);int status = bind(sockid, &addrport, size); –status: error status, = -1 if bind failed –sockid: integer, socket descriptor –addrport: struct sockaddr, the (IP) address and port of the machine (address usually set to INADDR_ANY – chooses a local address) –size: the size (in bytes) of the addrport structure

12 Netcomm Sockets The struct sockaddr The generic:The generic: struct sockaddr { u_short sa_family; char sa_data[14]; }; –sa_family specifies which address family is being usedspecifies which address family is being used determines how the remaining 14 bytes are useddetermines how the remaining 14 bytes are used The Internet-specific:The Internet-specific: struct sockaddr_in { short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; }; –sin_family = AF_INET –sin_port: port # ( ) –sin_addr: IP-address –sin_zero: unused

13 Netcomm Sockets Address and port byte-ordering r Problem: m different machines / OS’s use different word orderings little-endian: lower bytes first big-endian: higher bytes first m these machines may communicate with one another over the network Big-Endian machine Little-Endian machine

14 Netcomm Sockets Network Byte Order All values stored in a sockaddr_in must be in network byte order.All values stored in a sockaddr_in must be in network byte order. –sin_port a TCP/IP port number. –sin_addr an IP address.

15 Netcomm Sockets Connection Setup (SOCK_STREAM) A connection occurs between two kinds of participantsA connection occurs between two kinds of participants –passive: waits for an active participant to request connection –active: initiates connection request to passive side Once connection is established, passive and active participants are “similar”Once connection is established, passive and active participants are “similar” –both can send & receive data –either can terminate the connection

16 Netcomm Sockets Connection setup cont’d Passive participantPassive participant –step 1: listen (for incoming requests) –step 3: accept (a request) –step 4: data transfer The accepted connection is on a new socketThe accepted connection is on a new socket The old socket continues to listenThe old socket continues to listen Active participantActive participant –step 2: request & establish connection –step 4: data transfer Passive Participant l-socka-sock-1a-sock-2 Active 1 socket Active 2 socket

17 Netcomm Sockets Connection est.: listen() & accept() Called by passive participantCalled by passive participant int status = listen(sock, queuelen);int status = listen(sock, queuelen); –status: 0 if listening, -1 if error –sock: integer, socket descriptor –queuelen: integer, # of active participants that can “wait” for a connection int s = accept(sock, &name, &namelen);int s = accept(sock, &name, &namelen); –s: integer, the new socket (used for data-transfer) –sock: integer, the orig. socket (being listened on) –name: struct sockaddr, address of the active participant –namelen: sizeof(name): value/result parameter

18 Netcomm Sockets Connection est.: connect() Called by active participantCalled by active participant int status = connect(sock, &name, namelen);int status = connect(sock, &name, namelen); –status: 0 if successful connect, -1 otherwise –sock: integer, socket to be used in connection –name: struct sockaddr: address of passive participant –namelen: integer, sizeof(name)