Part 1_Network Computing

download Part 1_Network Computing

of 114

Transcript of Part 1_Network Computing

  • 8/13/2019 Part 1_Network Computing

    1/114

    Network programming

    Lesson 1

    HUYNH Cong Phap, [email protected], [email protected]

    mailto:[email protected]:[email protected]:[email protected]:[email protected]
  • 8/13/2019 Part 1_Network Computing

    2/114

    ClientServer Computing

  • 8/13/2019 Part 1_Network Computing

    3/114

    Client Server Architecture

    A networkarchitecture in which

    each computer or

    process on the

    network is either a

    clientor a server.

  • 8/13/2019 Part 1_Network Computing

    4/114

    Components

    Clients Servers

    Communication Networks

    Client

    Server

  • 8/13/2019 Part 1_Network Computing

    5/114

    Applications that run on computers Rely on servers for

    Files

    Devices

    Processing power

    Example: E-mail client

    An application that enables you to send andreceive e-mail

    Clients

    Clients are Applications

  • 8/13/2019 Part 1_Network Computing

    6/114

    Servers

    Computers or processes that managenetwork resources

    Disk drives (file servers)

    Printers (print servers) Network traffic (network servers)

    Example: Database Server

    A computer system that processes databasequeries

    Servers Manage

    Resources

  • 8/13/2019 Part 1_Network Computing

    7/114

    Communication Networks

    Networks Connect

    Clients and

    Servers

  • 8/13/2019 Part 1_Network Computing

    8/114

    ClientServer Computing

    Process takes place on the server and

    on the client

    Servers Store and protect data

    Process requests from clients

    Clients

    Make requests

    Format data on the desktop

    Client-Server

    Computing Optimizes

    Computing Resources

  • 8/13/2019 Part 1_Network Computing

    9/114

    Application Functions

    Software applicationfunctions are separated

    into three distinct parts

    Client: Presentation & Application Logic

    Server:

    Data Management

  • 8/13/2019 Part 1_Network Computing

    10/114

    Application Components

    Data Management

    Application Logic

    Presentation

    3 Logical Tiers

    1

    2

    3

    Database Applications:

    Most common use of client-server architectures

    Thin

    Client

    FatClient

    2 Client Types

  • 8/13/2019 Part 1_Network Computing

    11/114

    Middleware

    Software that connects twootherwise separate applications

    Example: Middleware product

    linking a database system to a

    Web server

    Client: Requests Data via Web

    Database Server:

    Manages Data

    Web Server:

    Presents Dynamic Pages

    Middleware Links

    Applications

  • 8/13/2019 Part 1_Network Computing

    12/114

    Types of Servers

    Application Servers

    Audio/Video Servers

    Chat Servers

    Fax Servers

    FTP Servers

    Groupware Servers

    IRC Servers

    List Servers

    Mail Servers

    News Servers

    Proxy Servers

    Telnet Servers

    Web Servers

    Z39.50 Servers

    Source: http://webopedia.lycos.com

    From A to Z

  • 8/13/2019 Part 1_Network Computing

    13/114

    ADVANTAGES OF CLIENT-

    SERVERAdvantages often cited include:

    Centralization - access, resources, and data

    security are controlled through the server

    Scalability - any element can be upgradedwhen needed

    Flexibility - new technology can be easily

    integrated into the system

    Interoperability - all components (clients,

    network, servers) work together

  • 8/13/2019 Part 1_Network Computing

    14/114

    DISADVANTAGES OF

    CLIENT-SERVER Disadvantages often cited include:

    Dependability - when the server goes down,

    operations cease

    Higher than anticipated costs Can cause network congestion

  • 8/13/2019 Part 1_Network Computing

    15/114

    CLIENT-SERVER

    ARCHITECTURES There are basically two types of client-

    server architectures

    Two tier architectures

    Three tier architectures The choice between the two should be

    made based on combination of:

    Schedule for project implementation Expected system changes and

    enhancements

  • 8/13/2019 Part 1_Network Computing

    16/114

    TWO-TIER ARCHITECTURES

    Application components aredistributed between the

    server and client software

    In addition to part of the

    application software, the

    server also stores the data,

    and all data accesses are

    through the server. The presentation (to the

    user) is handled strictly by

    the client software.

    Server

    Network

    PC PC PC

    Clients

  • 8/13/2019 Part 1_Network Computing

    17/114

    TWO-TIER ARCHITECTURES

    (cont.) The PC clients assume the bulk of the

    responsibility for the application logic.

    The server assumes the bulk of the

    responsibility for data integrity checks,query capabilities, data extraction and

    most of the data intensive tasks,

    including sending the appropriate data tothe appropriate clients.

  • 8/13/2019 Part 1_Network Computing

    18/114

    TWO-TIER ARCHITECTURES,

    ADVANTAGES The commonly cited advantages of two-

    tier systems include:

    Fast application development time

    Available tools are robust and lendthemselves to fast prototyping to insure user

    needs a met accurately and completely.

    Conducive to environments with

    homogeneous clients, homogeneous

    applications, and static business rules.

  • 8/13/2019 Part 1_Network Computing

    19/114

    TWO-TIER ARCHITECTURES,

    DISADVANTAGES The commonly cited disadvantages of

    two-tier systems include:

    Not suitable for dispersed, heterogeneous

    environments with rapidly changing businessrules.

    Because the bulk of the application logic is

    on the client, there is the problem of client

    software version control and new versionredistribution.

    Security can be complicated because a user

    may require separate passwords for eachSQL server accessed.

  • 8/13/2019 Part 1_Network Computing

    20/114

  • 8/13/2019 Part 1_Network Computing

    21/114

    THREE-TIER

    ARCHITECTURES (cont.) When data or processing are required by

    the presentation client, a call is made to

    the middle-tier functionality server.

    This tier performs calculations, doesreports, and makes any needed client

    calls to other servers (e.g.. a data base

    server).

  • 8/13/2019 Part 1_Network Computing

    22/114

    THREE-TIER

    ARCHITECTURES (cont.) Middle tier servers are usually coded in a

    highly portable, non-proprietary language

    such as C or C++.

    Middle tier servers may be multithreadedand can be accessed by multiple clients.

    The calling mechanism from client to

    server and from server to server is bymeans of RPCs.

  • 8/13/2019 Part 1_Network Computing

    23/114

    -ARCHITECTURES,

    ADVANTAGES (cont.) Commonly cited advantages include: Having separate functionality servers allows

    for the parallel development of individual tiers

    by application specialists. Provides for more flexible resource

    allocation. Can reduce network traffic by

    having the functionality servers strip data to

    the precise structure needed before sendingit to the clients.

  • 8/13/2019 Part 1_Network Computing

    24/114

    -ARCHITECTURES,

    DISADVANTAGES Often cited disadvantages of 3-tierarchitectures include:

    Creates an increased need for network traffic

    management, server load balancing, andfault tolerance.

    Current tools are relatively immature and are

    more complex.

    Maintenance tools are currently inadequatefor maintaining server libraries. This is a

    potential obstacle for simplifying

    maintenance and promoting code reuse

    throu hout the or anization.

  • 8/13/2019 Part 1_Network Computing

    25/114

    Peer to Peer Computing

  • 8/13/2019 Part 1_Network Computing

    26/114

    What is Peer-to-Peer?

    A model of communication where everynode in the network acts alike.

    As opposed to the Client-Server model,where one node provides services and

    other nodes use the services.

  • 8/13/2019 Part 1_Network Computing

    27/114

    Advantages of P2P Computing

    No central point of failure E.g., the Internet and the Web do not have a central

    point of failure.

    Most internet and web services use the client-server

    model (e.g. HTTP), so a specific service does have acentral point of failure.

    Scalability

    Since every peer is alike, it is possible to add more

    peers to the system and scale to larger networks.

  • 8/13/2019 Part 1_Network Computing

    28/114

    Disadvantages of P2P

    Computing Decentralized coordination

    How to keep global state consistent?

    Need for distributed coherency protocols.

    All nodes are not created equal. Computing power, bandwidth have an impact

    on overall performance.

    ProgrammabilityAs a corollary of decentralized coordination.

  • 8/13/2019 Part 1_Network Computing

    29/114

    P2P Computing Applications

    File sharing

    Process sharing

    Collaborative environments

  • 8/13/2019 Part 1_Network Computing

    30/114

    P2P File Sharing Applications

    Improves data availability Replication to compensate for failures.

    E.g., Napster, Gnutella, Freenet, KaZaA

    (FastTrack), your DFS project.

    2 S

  • 8/13/2019 Part 1_Network Computing

    31/114

    P2P Process Sharing

    Applications

    For large-scale computations

    Data analysis, data mining, scientific

    computing E.g., SETI@Home, Folding@Home,

    distributed.net, World-Wide Computer

    mailto:SETI@Homemailto:Folding@Homemailto:Folding@Homemailto:SETI@Home
  • 8/13/2019 Part 1_Network Computing

    32/114

    P2P Collaborative Applications

    For remote real-time humancollaboration.

    Instant messaging, virtual meetings,shared whiteboards, teleconferencing,tele-presence.

    E.g., talk, IRC, ICQ, AOL Messenger,

    Yahoo! Messenger, Jabber, MSNetmeeting, NCSA Habanero, Games

  • 8/13/2019 Part 1_Network Computing

    33/114

    Types of P2P

    Pure P2P

    Hybrid P2P

  • 8/13/2019 Part 1_Network Computing

    34/114

    Napster

  • 8/13/2019 Part 1_Network Computing

    35/114

    Gnutella

    But introduces a new single point of failure!

  • 8/13/2019 Part 1_Network Computing

    36/114

    KaZaA/Morpheus

  • 8/13/2019 Part 1_Network Computing

    37/114

    Distributed systems

    Data Networking &Client-Server Communication

  • 8/13/2019 Part 1_Network Computing

    38/114

    Distributed systems

    Independent machines workcooperatively without shared memory

    They have to talk somehow

    Interconnect is the network

  • 8/13/2019 Part 1_Network Computing

    39/114

    Modes of connection

    Circuit-switched dedicated path

    guaranteed (fixed) bandwidth

    [almost] constant latencyPacket-switched

    shared connection

    data is broken into chunks called packets each packet contains destination address

    available bandwidth channel capacity

    variable latency

  • 8/13/2019 Part 1_Network Computing

    40/114

    Whats in the data?

    For effective communication same language, same conventions

    For computers:

    electrical encoding of data where is the start of the packet?

    which bits contain the length?

    is there a checksum? where is it?how is it computed?

    what is the format of an address?

    byte ordering

  • 8/13/2019 Part 1_Network Computing

    41/114

    Protocols

    These instructions and conventions

    are known as protocols

  • 8/13/2019 Part 1_Network Computing

    42/114

    Protocols

    Exist at different levelsunderstand format ofaddress and how tocompute checksum

    request web page

    humans vs. whalesdifferent wavelengths

    French vs. Hungarian

    versus

  • 8/13/2019 Part 1_Network Computing

    43/114

    Layering

    To ease software development andmaximize flexibility:

    Network protocols are generally organized

    in layers Replace one layer without replacing

    surrounding layers

    Higher-level software does not have toknow how to format an Ethernet packet

    or even know that Ethernet is beingused

  • 8/13/2019 Part 1_Network Computing

    44/114

    Layering

    Most popular model of guiding(not specifying) protocol layers is

    OSI reference model

    Adopted and created by ISO

    7 layers of protocols

  • 8/13/2019 Part 1_Network Computing

    45/114

    OSI Reference Model: Layer 1

    Transmits andreceives raw data to

    communication

    medium.

    Does not care about

    contents.

    voltage levels, speed,

    connectors

    Physical1Examples: RS-232, 10BaseT

  • 8/13/2019 Part 1_Network Computing

    46/114

    Data Link

    OSI Reference Model: Layer 2

    Detects and corrects errors.

    Organizes data into packets

    before passing it down.

    Sequences packets (if

    necessary).

    Accepts acknowledgements

    from receiver.

    Physical1

    2

    Examples: Ethernet MAC, PPP

  • 8/13/2019 Part 1_Network Computing

    47/114

    Network

    Data Link

    OSI Reference Model: Layer 3

    Relay and routeinformation to

    destination.

    Manage journey ofpackets and figure out

    intermediate hops (if

    needed).

    Physical1

    2

    3

    Examples: IP, X.25

  • 8/13/2019 Part 1_Network Computing

    48/114

    Transport

    Network

    Data Link

    OSI Reference Model: Layer 4

    Provides a consistentinterface for end-to-end(application-to-application)

    communication.Manages flow control.

    Network interface issimilar to a mailbox.

    Physical1

    2

    3

    4

    Examples: TCP, UDP

  • 8/13/2019 Part 1_Network Computing

    49/114

    Session

    Transport

    Network

    Data Link

    OSI Reference Model: Layer 5

    Services to coordinatedialogue and managedata exchange.

    Software implemented

    switch.

    Manage multiple logicalconnections.

    Keep track of who istalking: establish & endcommunications.Physical1

    2

    3

    4

    5

    Examples: HTTP 1.1, SSL,

    NetBIOS

  • 8/13/2019 Part 1_Network Computing

    50/114

    Presentation

    Session

    Transport

    Network

    Data Link

    OSI Reference Model: Layer 6

    Data representation

    Concerned with the

    meaning of data bits

    Convert between

    machine

    representations

    Physical1

    2

    3

    4

    5

    6

    Examples: XDR, ASN.1,

    MIME, MIDI

  • 8/13/2019 Part 1_Network Computing

    51/114

    Application

    Presentation

    Session

    Transport

    Network

    Data Link

    OSI Reference Model: Layer 7

    Collection ofapplication-specificprotocols

    Physical1

    2

    3

    4

    5

    6

    7

    Examples:email (SMTP, POP, IMAP)file transfer (FTP)

    directory services (LDAP)

  • 8/13/2019 Part 1_Network Computing

    52/114

    Some networkingterminology

  • 8/13/2019 Part 1_Network Computing

    53/114

    Local Area Network (LAN)

    Communications network small area (building, set of buildings)

    same, sometimes shared, transmissionmedium

    high data rate (often): 1 Mbps1 Gbps

    Low latency

    devices are peers

    any device can initiate a data transfer with anyother device

    Most elements on a LAN are workstations endpoints on a LAN are called nodes

  • 8/13/2019 Part 1_Network Computing

    54/114

    Connecting nodes to LANs

    ?

    network computer

  • 8/13/2019 Part 1_Network Computing

    55/114

    Connecting nodes to LANsnetwork computer

    Adapter expansion slot (PCI, PC Card, USB dongle)

    usually integrated onto main board

    Network adapters are referred to as

    Network Interface Cards(NICs) or

    adapters

  • 8/13/2019 Part 1_Network Computing

    56/114

    Media

    Wires (or RF, IR) connecting together thedevices that make up a LAN

    Twisted pair Most common:

    STP: shielded twisted pair

    UTP: unshielded twisted pair(e.g. Telephone cable, Ethernet 10BaseT)

    Coaxial cable Thin (similar to TV cable)

    Thick (e.g., 10Base5, ThickNet)

    Fiber

    Wireless

  • 8/13/2019 Part 1_Network Computing

    57/114

  • 8/13/2019 Part 1_Network Computing

    58/114

    Networking Topology

    Bus Network

  • 8/13/2019 Part 1_Network Computing

    59/114

    Networking Topology

    Tree Network

  • 8/13/2019 Part 1_Network Computing

    60/114

    Networking Topology

    Star Network

  • 8/13/2019 Part 1_Network Computing

    61/114

    Networking Topology

    Ring Network

  • 8/13/2019 Part 1_Network Computing

    62/114

    Networking Topology

    Mesh Network

  • 8/13/2019 Part 1_Network Computing

    63/114

    Clients and Servers

    Send messages to applications

    not just machines

    Client must get data to the desiredprocess

    server process must get data back to client

    process

    To offer a service, a server must get a

    transport addressfor a particular service

    -

  • 8/13/2019 Part 1_Network Computing

    64/114

    Machine address

    versus

    Transport address

  • 8/13/2019 Part 1_Network Computing

    65/114

    Transport provider

    Layer of software that accepts a networkmessage and sends it to a remote

    machine

    Two categories:

    connection-oriented protocols

    connectionless protocols

  • 8/13/2019 Part 1_Network Computing

    66/114

    Connection-oriented Protocols

    1. establish connection2. [negotiate protocol]3. exchange data4. terminate connection

  • 8/13/2019 Part 1_Network Computing

    67/114

    Connection-oriented Protocols

    virtual circuit service provides illusion of having a dedicated circuit

    messages guaranteed to arrive in-order

    application does not have to address eachmessage

    vs. circuit-switched service

    1. establish connection2. [negotiate protocol]3. exchange data4. terminate connection

    dial phone number[decide on a language]speakhang up

    analogous to phone call

    C

  • 8/13/2019 Part 1_Network Computing

    68/114

    Connectionless Protocols

    - no call setup- send/receive data

    (each packet addressed)- no termination

    C i l P l

  • 8/13/2019 Part 1_Network Computing

    69/114

    Connectionless Protocols

    datagram service

    client is not positive whether message arrived

    at destination

    no state has to be maintained at client orserver

    cheaper but less reliable than virtual circuit

    service

    - no call setup- send/receive data

    (each packet addressed)- no termination

    drop letter in mailbox(each letter addressed)

    analogous to mailbox

    Eth t

  • 8/13/2019 Part 1_Network Computing

    70/114

    Ethernet

    Layers 1 & 2 of OSI model Physical (1)

    Cables: 10Base-T, 100Base-T, 1000Base-T, etc.

    Data Link (2) Ethernet bridging

    Data frame parsing

    Data frame transmission

    Error detection

    Unreliable, connectionless communication

    Eth t

  • 8/13/2019 Part 1_Network Computing

    71/114

    Ethernet

    48-byte ethernet address Variable-length packet

    1518-byte MTU

    18-byte header, 1500 bytes data

    Jumbo packets for Gigabit ethernet

    9000-byte MTUdest addr src addr

    frametype

    6 bytes 6 bytes 2

    data (payload) CRC

    446-1500 bytes

    18 bytes + data

    IP I t t P t l

  • 8/13/2019 Part 1_Network Computing

    72/114

    IPInternet Protocol

    Born in 1969 as a research network of 4machines

    Funded by DoDs ARPA

    Goal:build an efficient fault-tolerant networkthat could connect heterogeneous

    machines and link separately connectednetworks.

    I t t P t l

  • 8/13/2019 Part 1_Network Computing

    73/114

    Internet Protocol

    Connectionless protocol designed to handlethe interconnection of a large number of loc

    and wide-area networks that comprise the

    internet

    IP can route from one physical network to

    another

  • 8/13/2019 Part 1_Network Computing

    74/114

    IP Add

  • 8/13/2019 Part 1_Network Computing

    75/114

    IP Address space

    32-bit addresses>4 billion addresses!

    Routers would need a table of 4 billion

    entries

    Design routing tables so one entry can

    match multiple addresses hierarchy: addresses physically close will

    share a common prefix

    IP Addressing: networks &

  • 8/13/2019 Part 1_Network Computing

    76/114

    IP Addressing: networks &

    hosts

    first 16 bits identify Rutgers

    external routers need only one entry

    route 128.6.*.* to Rutgers

    cs.rutgers.edu

    128.6.4.2

    80 06 04 02

    remus.rutgers.edu

    128.6.13.3

    80 06 0D 03

    network # host #

    IP Addressing: networks &

  • 8/13/2019 Part 1_Network Computing

    77/114

    g &

    hosts

    IP address network #:identifies network machine

    belongs to

    host #:identifies host on the network

    use network number to route packet to

    correct network

    use host number to identify specific

    machine

    IP Add i

  • 8/13/2019 Part 1_Network Computing

    78/114

    IP Addressing

    Expectation: a few big networks and many small ones

    create different classesof networks

    use leading bits to identify network

    To allow additional networks within an organization:use high bits of host number for anetwork within a network subnet

    class leading bits bits for net # bits for host

    A 0 7 (128) 24 (16M)

    B 10 14 (16K) 16 (64K)

    C 110 21 (2M) 8 (256)

    IP Add i

  • 8/13/2019 Part 1_Network Computing

    79/114

    IP Addressing

    IBM: 9.0.0.09.255.255.25500001001 xxxxxxxx xxxxxxxx xxxxxxxxx

    network #8 bits

    host #24 bits

    00001001 10101010 11 xxxxxx xxxxxxxxx

    network #18 bits

    host #14 bits

    Subnet within IBM (internal routers only)

    R i t f dd

  • 8/13/2019 Part 1_Network Computing

    80/114

    Running out of addresses

    Huge growth

    Wasteful allocation of networks

    Lots of unused addresses

    Every machine connected to the internet

    needed a worldwide-unique IP address

    Solutions: CIDR, NAT, IPv6

    IP Special Addresses

  • 8/13/2019 Part 1_Network Computing

    81/114

    IP Special Addresses

    All bits 0 Valid only as source address

    all addresses for this machine

    Not valid over network

    All host bits 1 Valid only as destination

    Broadcast to network

    All bits 1 Broadcast to all directly connected networks

    Leading bits 1110 Class D network

    127.0.0.0: reserved for local traffic 127.0.0.1 usuall assi ned to loo back device

    IPv6 vs IPv4

  • 8/13/2019 Part 1_Network Computing

    82/114

    IPv6 vs. IPv4

    IPv4 4 byte (32 bit) addresses

    IPv6: 16-byte (128 bit) addresses

    3.6 x 1038possible addresses

    8 x 1028times more addresses than IPv4

    4-bit priority field

    Flow label (24-bits)

    Network Address Translation

  • 8/13/2019 Part 1_Network Computing

    83/114

    (NAT)

    External IP address24.225.217.243

    InternalIP address192.168.1.x

    External

    addressExt

    portInternal

    addressInt

    port

    24.225.217.243 25 192.168.1.1 3455

    24.225.217.243 25 192.168.1.2 11231

    24.225.217.243 80 192.168.1.1 12482

    24.225.217.243 80 192.168.1.3 21908

    .1 .2 .3 .4 .5

    Getting to the machine

  • 8/13/2019 Part 1_Network Computing

    84/114

    Getting to the machine

    IP is a logical network on top of multiple

    physical networks

    OS support for IP: IP driver

    IP driver

    network driver

    send data

    send packet

    to wirefrom wire

    receive packet

    receive data

    IP driver responsibilities

  • 8/13/2019 Part 1_Network Computing

    85/114

    IP driver responsibilities

    Get operating parameters from devicedriver Maximum packet size (MTU)

    Functions to initialize HW headers

    Length of HW header

    Routing packets From one physical network to another

    Fragmenting packets Send operations from higher-layers

    Receiving data from device driver

    Dropping bad/expired data

    Device driver responsibilities

  • 8/13/2019 Part 1_Network Computing

    86/114

    Device driver responsibilities

    Controls network interface card Comparable to character driver

    Processes interrupts from networkinterface Receive packets

    Send them to IP driver

    Get packets from IP driver Send them to hardware

    Ensure packet goes out without collision

    bottomh

    alf

    tophalf

    Network device

  • 8/13/2019 Part 1_Network Computing

    87/114

    Network device

    Network card examines packets on wire Compares destination addresses

    Before packet is sent, it must beenvelopedfor the physical network

    deviceheader

    payload

    IP header IP data

    Device addressing

  • 8/13/2019 Part 1_Network Computing

    88/114

    Device addressing

    IP addressethernet address

    Address Resolution Protocol(ARP)

    1. Check local ARP cache2. Send broadcast message requesting

    ethernet address of machine with certain

    IP address

    3. Wait for response (with timeout)

    Transport-layer protocols over

  • 8/13/2019 Part 1_Network Computing

    89/114

    y

    IP

    IP sends packets to machine No mechanism for identifying sending or

    receiving application

    Transport layer uses a port numberto

    identify the application

    TCPTransmission Control Protocol

    UDPUser Datagram Protocol

    TCPTransmission Control

  • 8/13/2019 Part 1_Network Computing

    90/114

    Protocol

    Virtual circuit service(connection-oriented)

    Send acknowledgement for each

    received packet Checksum to validate data

    Data may be transmitted simultaneously

    in both directions

  • 8/13/2019 Part 1_Network Computing

    91/114

  • 8/13/2019 Part 1_Network Computing

    92/114

    Headers: TCP & UDP

  • 8/13/2019 Part 1_Network Computing

    93/114

    Headers: TCP & UDPdevice

    headerIP header IP data

    TCP/UDP

    header

    src port dest port

    seq number

    ack number

    hdrlen flags

    checksum urgent ptr

    options and pad

    - window

    src port dest port

    seg length checksum

    TCP header UDP header

    20

    bytes

    8 bytes

    payload

    Device header (Ethernet II)

  • 8/13/2019 Part 1_Network Computing

    94/114

    Device header (Ethernet II)device

    headerIP header IP data

    TCP/UDP

    header

    dest addr src addr frametype

    6 bytes 6 bytes 2

    data CRC

    446-1500 bytes

    18 bytes + data

    payload

    Quality of Service Problems in

  • 8/13/2019 Part 1_Network Computing

    95/114

    IP

    Too much traffic Congestion

    Inefficient packet transmission

    59 bytes to send 1 byte in TCP/IP!

    20 bytes TCP + 20 bytes IP + 18 bytes

    ethernet

    Unreliable delivery Software to the rescueTCP/IP

    Unpredictable packet delivery

  • 8/13/2019 Part 1_Network Computing

    96/114

    Sockets

  • 8/13/2019 Part 1_Network Computing

    97/114

    Sockets

    IP lets us send data between machines

    TCP & UDP are transport layer protocols

    Contain port numberto identify transportendpoint (application)

    One popular abstraction for transportlayer connectivity: sockets

    Developed at Berkeley

    Sockets

  • 8/13/2019 Part 1_Network Computing

    98/114

    Sockets

    Attempt at generalized IPC modelGoals:

    communication between processes should

    not depend on whether they are on thesame machine

    efficiency

    compatibility

    support different protocols and naming

    conventions

    Socket

  • 8/13/2019 Part 1_Network Computing

    99/114

    Socket

    Abstract object from which messages aresent and received

    Looks like a file descriptor

    Application can select particular style ofcommunication

    Virtual circuit, datagram, message-based, in-

    order delivery

    Unrelated processes should be able tolocate communication endpoints

    Sockets should be named

    Name meaningful in the communications

    domain

  • 8/13/2019 Part 1_Network Computing

    100/114

  • 8/13/2019 Part 1_Network Computing

    101/114

    Step 2

  • 8/13/2019 Part 1_Network Computing

    102/114

    Step 2

    Name the socket (assign address, port)int error = bind(s, addr, addrlen)

    socket Address structurestruct sockaddr*length ofaddressstructure

    Step 3a (server)

  • 8/13/2019 Part 1_Network Computing

    103/114

    Step 3a (server)

    Set socket to be able to accept connectionsint error = listen(s, backlog)

    socketqueue length forpending connections

    Step 3b (server)

  • 8/13/2019 Part 1_Network Computing

    104/114

    Step 3b (server)

    Wait for a connection from clientint snew = accept(s, clntaddr, &clntalen)

    socketpointer to addressstructure

    length ofaddressstructurenew socket

    for this session

    Step 3 (client)

  • 8/13/2019 Part 1_Network Computing

    105/114

    Step 3 (client)

    Connect to serverint error = connect(s, svraddr, svraddrlen)

    socket Address structurestruct sockaddr*length ofaddressstructure

    Step 4

  • 8/13/2019 Part 1_Network Computing

    106/114

    Step 4

    Exchange dataConnection-oriented

    read/writerecv/send (extra flags)

    Connectionlesssendto, sendmsg

    recvfrom, recvmsg

    Step 5

  • 8/13/2019 Part 1_Network Computing

    107/114

    Step 5

    Close connectionshutdown(s, how)

    how:0: can send but not receive1: cannot send more data2: cannot send or receive (=0+1)

    Sockets in Java

  • 8/13/2019 Part 1_Network Computing

    108/114

    Sockets in Java

    java.net package

    Two major classes:

    Socket: client-side

    ServerSocket: server-side

    Step 1a (server)

  • 8/13/2019 Part 1_Network Computing

    109/114

    Step 1a (server)

    Create socket and name itServerSocket svc =

    new ServerSocket(port)

    Step 1b (server)

  • 8/13/2019 Part 1_Network Computing

    110/114

    Step 1b (server)

    Wait for connection from clientServer req = svc.accept()

    new socket for client session

    Step 1 (client)

  • 8/13/2019 Part 1_Network Computing

    111/114

    Step 1 (client)

    Create socket and name itSocket s = new Socket(address, port);

    obtained from:getLocalHost, getByName,or getAllByName

    Socket s =

    new Socket(cs.rutgers.edu, 2211);

    Step 2

  • 8/13/2019 Part 1_Network Computing

    112/114

    Step 2

    Exchange dataobtain InputStream/OutputStream from

    Socket object

    BufferedReader in =

    new BufferedReader(

    new InputStreamReader(

    s.getInputStream()));

    PrintStream out =new PrintStream(s.getOutputStream());

    Step 3

  • 8/13/2019 Part 1_Network Computing

    113/114

    Step 3

    Terminate connectionclose streams, close socket

    in.close();

    out.close();s.close();

  • 8/13/2019 Part 1_Network Computing

    114/114