DCN 3013: Network Programming - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

DCN 3013: Network Programming

Description:

User Datagram Protocol (UDP) provides fewer services and requires more control ... There is no handshaking or confirmation that the other system is listening, ... – PowerPoint PPT presentation

Number of Views:326
Avg rating:3.0/5.0
Slides: 15
Provided by: notesU
Category:

less

Transcript and Presenter's Notes

Title: DCN 3013: Network Programming


1
DCN 3013 Network Programming
  • Muhammed Ramiza Ramli
  • KUKTEM

2
Overview of UDP
  • User Datagram Protocol (UDP) provides fewer
    services and requires more control by the
    programmer
  • UDP is a connectionless protocol without
    guaranteed message delivery

3
UDP versus TCP
  • UDP handles fewer detail than TCP
  • does not ensure that messages are delivered (no
    report)?
  • not ensure the order in which packets will be
    transferred (IP will split the packet)?

4
Advantages of TCP
  • There are several advantages of TCP
  • provides explicit connection creation and
    termination
  • ensure reliable, ordered and unduplicated
    delivery of data
  • handles flow control
  • allow prioritization of data
  • return an error condition if data is not
    delivered
  • handles large data block by maintaining the
    connection and breaking the blocks into smaller
    pieces

5
Disadvantages of TCP
  • Disagvantages
  • a connection must be created and maintained while
    data is moving. making it slower - overhead

6
Advantages of UDP
  • Advantages
  • does not require a connection
  • does not have the overhead of receiver
    acknowledging receipt of packets
  • designed for a short application and control
    messages
  • packet by packet basis requires less network
    bandwidth than TCP

7
Disadvantages of UDP
  • Disadvantages
  • programmer must create code to detect
    transmission error and retransmit (if required by
    application)?
  • programmer must break down the larger packet

8
Why UDP?
  • Look at how an application works.
  • An application that sends out periodic message
    that are low importance or repeated
  • An application that regularly broadcast status
    (periodic status)?
  • based on importance of the data, volume of the
    data, and what level of transmission integrity.

9
TCP
  • Client
  • Create socket
  • socket()?
  • Initiate a connection
  • connect()?
  • Communicate
  • send()/recieve()?
  • Server
  • Create socket
  • socket()?
  • Assign a name to the socket
  • bind()?
  • Establish a queue
  • listen()?
  • Extract connection from a queu
  • accept()?
  • Communicate
  • send()/recieve()?

10
UDP
  • Server
  • Create a socket
  • socket()?
  • Assign a name to the socket
  • bind
  • receive data from client
  • recvfrom
  • send data to client
  • sendto
  • Client
  • Create a socket
  • socket()?
  • Assign a name to the socket
  • bind
  • send data to server
  • snedto()?
  • receive data from server
  • recvfrom()?

11
Sending Data with UDP
  • There is no handshaking or confirmation that the
    other system is listening, receiving, or ever
    processing the data
  • include ltsys/types.hgt
  • include ltsys/socket.hgt
  • int sendto( int s, const void msg, size_t len,
    int flags, const struct sockaddr to, socklen_t
    tolen)

12
Program
  • int port 6789
  • int socket_df
  • char buf80
  • struct sockaddr_in address
  • address.sin_family AF_INET
  • address.sin_addr.s_addr inet_addr(127.0.0.1)
  • address.sin_port htons(port)
  • convert the integer passed from host byte order
    to network byte order.
  • socket_df socket(AF_INET, SOCK_DGRAM, 0)
  • sendto(socket_df, buf, sizeof(buf), 0, (struct
    sockaddr) address, sizeof(address))
  • close(socket_df)

13
receiving UDP Data
  • UDP listen to a port for messages tranmitted from
    another system
  • include ltsys/types.hgt
  • include ltsys/socket.hgt
  • int recvfrom(int s, void buf, size_t len, int
    flags, struct socketaddr from, socklen_t
    fromlen)

14
program
  • int port 6789
  • int sin_len
  • char msg80
  • int sock_df
  • struct sockaddr_in sin
  • sin.sin_family AF_INET
  • sin.sin_addr.s_addr htonl(INADDR_ANY)
  • sin.sin_port htons(port)
  • sin_len sizeof(sin)
  • sock_df socket(AF_INET,SOCK_DGRAM, 0)
  • bind(sock_df, (struct sockaddr )sin,
    sizeof(sin))
  • recvfrom(sock_df, msg, sizeof(msg), 0, (struct
    sockaddr) sin, sin_len)
  • close(sock_df)
Write a Comment
User Comments (0)
About PowerShow.com