Class A Addresses The 1 st bit of a class A address is 0 The 1 st byte has a value from 1-126. (128.x.x.x would not be a class A) 127.x.x.x is reserved.

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?
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
1 Advanced Name and Address Conversions getaddrinfo, getnameinfo, gai_strerror, freeaddrinfo host_serv, tcp_connect, tcp_listen, udp_client, udp_connect,
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
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.
Operating Systems Chapter 9 Distributed Communication.
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.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
Client-Side Network Programming
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
Week 13 - Wednesday.  What did we talk about last time?  Networking.
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.
Lab 5 Sockets. Useful Sockets Links (courtesy of Stanford University) Programming UNIX Sockets in C - Frequently Asked Questions
Advanced Sockets API-II Vinayak Jagtap
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
TELE 402 Lecture 6: Name and address conversions 1 Overview Last Lecture –Socket Options and elementary UDP sockets This Lecture –Name and address conversions.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
1 CS716 Advanced Computer Networks By A. Wahid Shaikh.
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
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.
Chapter 11 Advanced Name and Address Conversion. Introduction gethostbyname, gethostbyaddr: protocol dependent getaddrinfo: –a function providing protocol.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
1 Issues in Client/Server Refs: Chapter 27 Case Studies RFCs.
Socket Abstraction and Interprocess Communication
CSCE 313 Network Socket MP8 DUE: FRI MAY 5, 2017
Sockets and Beginning Network Programming
UNIX Sockets COS 461 Precept 1.
Advanced Computer Networks
CS 105 “Tour of the Black Holes of Computing”
Class A Addresses The 1st bit of a class A address is 0
Week 13 - Friday CS222.
Socket Programming in C
Name and Address Conversions Part I
Client-side Networking CSE 333 Spring 2018
תקשורת ומחשוב תרגול 3-5 סוקטים ב-C.
UNIX Sockets Outline Homework #1 posted by end of day
Socket Abstraction and Interprocess Communication
Socket Programming in C
TCP Sockets Programming
Socket Programming.
Advanced Sockets Programming
Issues in Client/Server Programming
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Server-side Programming CSE 333 Summer 2018
Client-side Networking CSE 333 Summer 2018
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Client-side Networking CSE 333 Autumn 2018
Socket Abstraction and Interprocess Communication
Client-side Networking CSE 333 Winter 2019
Client-side Networking CSE 333 Spring 2019
Presentation transcript:

Class A Addresses The 1 st bit of a class A address is 0 The 1 st byte has a value from (128.x.x.x would not be a class A) 127.x.x.x is reserved for loopback ( often used) x is used from broadcast x is used as a ‘default’ router This allows 16,277,214 ( ) hosts per class A network. Only a few class A licenses are not shared. covers 50% of the entire address space 0 7 bits/1 st byte 24 bits for host addresses/3 bytes

Class B Addresses The 1 st 2 bits of a class B address is 10 Allows for 2 14 or 16,384 network licences, hosts per network # 127.x.x.x is reserved for loopback ( often used) 126 network numbers x.x is used for broadcast x. x.0.0 is used as a ‘default’ router This allows 16,384 ( ) hosts per class A network Represents 25% of all available IP addresses 1 st byte is from 128 to bits 16 bits for host addresses/2 bytes

Class C Addresses The 1 st 3 bits of a class C address is 110 Allows for 2 21 or 2,097,152 network licences, 254 hosts per network 127.x.x.x is reserved for loopback ( often used) 126 network numbers x.x.x.255 is used for broadcast x. x.x.0 is used as a ‘default’ router Represents 12.5% of all available IP addresses first byte is bits/3 bytes 8 bits

Class D Addresses The 1 st 4 bits of a class B address is 1110 first byte is Reserved by the Internet Address Number Authority (IANA) for broadcast purposes 1110 Addresses from

Class E Addresses The 1 st 5 bits of a class B address is first byte is Reserved for experimental use 1110 Addresses from

Sockets And Connections (exploring Beej’s client and server program)

Writing a Client in C gettaddrinfo(...) – name+port -> IP address inet_ntop(...) - only needed to display address socket(...) - create an fd for the socket connect(...) - open the socket recv(...) - receive bytes from the socket close(...) or shutdown(..) – close the socekt

getaddrinfo(name,service,hints,result) name: a string, ie: humber.c service: a port# or service name, “80”, “http” hints: uses the addrinfo to suggest V4, V6... results: a linked list of addrinfo s

} int ai_flags; int ai_family; //AF_INET, AF_INET6, AF_UNIX // AF_UNSPE int ai_socktype; //SOCK_STREAM, SOCK_DGRAM int ai_protocol; size_t ai_addrlen; struct sockaddr *ai_addr; //different for V4, V6 char *ai_canonname; //not used? struct addinfo * ai_next; //it’s a linked list!jk struct addrinfo {

int socket(family,socketType,protocol) family: AF_INET, AF_INET6, AF_UNIX socketType: SOCK_STREAM, SOCK_DGRAM, SOCK_RAW,... protocol - set to zero. Most socket types have only one protocol so we can ignore this

connect(fd,ipAddr,addrLength) The fd is the local end of the socket the ipAddr is either V4 or V6 – a string addrLength is the length of the string Fails if the service is not available. Not used with SOCK_DGRAM (connectionless)

recv(fd,buf,bufsize,flags) exactly like read – except for the flags unless socket is non-blocking it waits for input we don’t use flags in the 1st example – MSG_DONTWAIT – MSG_ERRQUEUE – MSG_OOB – MSG_PEEK

close(fd) Yes, it’s really simple!!!!

shutdown(fd, how) ‘how’ is either SHUT_RD, SHUT_WR, SHUT_RDWR SHUT_WR used to signal an EOF to the other end If we have multiple threads SHUT_RDWR decrements a count leaving the socket open

Writing a Server in C gettaddrinfo(...) - info about this machine socket(...) create a socket setsockopt(...) - define properties of the socket bind(...) listen(...) - wait for a connection – this blocks freeaddrinfo() - return the linked list’s memory sigaction (...) - reap any dead child processes accept(...) - accept the connection inet_ntop(...) - not req’d: display the connection fork a child to carry on the conversation – send(...) (can also receive) – close(....) - close the connection

getaddrinfo(NULL,service,&hints,&result) NULL - not needed service - port or service name as a string hints – field.ai_flags is AI_PASSIVE – use this host – ai_socktype - SOCK_STREAM – ai_family - AF_UNSPEC - whatever. AF_INET, AF_INET6 Returns: a list of IP addresses, usually 1 or an error code – service may be in use

int socket(family,socketType,protocol) family: AF_INET, AF_INET6, AF_UNIX socketType: SOCK_STREAM, SOCK_DGRAM, SOCK_RAW,... protocol - set to zero. Most socket types have only one protocol so we can ignore this

setsockopt(fd,level,optname,&value,len) Used to set socket characteristics fd – the socket id from call to socket() level – always SOL_SOCKET - it corresponds to the protocol, and we don’t have any optname: SO_REUSEADDR - set this to 1/true other options will come up later. For a list of options, see: man 7 socket value - settings for options may be different data structures – pass an address len

bind(fd,addressInfo,length) fd – the socket we just opened addressInfo - AF_type, port – we have to and will match the info in the call to socket length – size bind generates a name for the socket in the proc directory. In the client program, the call to socket only connects to an existing socket. ONLY THE SUPERUSER can use a port <1024 If the ip address is 0 (INADDR_ANY) then you can bind to any network card in the machine.

listen(fd,nItems) Sets up a queue for the socket of nItems. If a server is busy handling a connection it might miss the next request for one, even if we fork quickly. However if the average interarrival time is too high, no size may be big enough. This is to handle surges in requests, ie: when a class logs into a service all at once.

int accept(fd, &theirAddr, length) blocks/waits for a connection returns their addresss info and the bidirectional socket to talk to

send(fd,buffer,length, flags) send a message to the client

close(fd) Yes, it’s that simple Can also use shutdown(fd,how)

Other Management Tasks memset(&memoryBlock,val, nBytes) freeaddrinfo(serverInfo) sigemptyset(signalset) – clears all signal handlers sigaction(SIGHCHILD, handler,lastUse) - advanced version of signal(signum,handler) - it can be ignored. Use ps and kill -9 to terminate rogue children