114101403 network programming week one orientation

Upload: cos-c-jasti

Post on 04-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 114101403 Network Programming Week One Orientation

    1/20

    Network programming

    Manjunath.

  • 7/30/2019 114101403 Network Programming Week One Orientation

    2/20

    Administrative issues (1)

    Instructors: Manjunath Mattam

    Moodle and Mediawiki support: Mohana Krishna

    Group mailing list: [email protected]

    Courses slides, tasks, readings, in local mediawiki.

    Submissions in moodle only. Text book:UNIX Network Programming Volume 1,

    Third Edition: The Sockets Networking API Other text books available in references section.

    mailto:[email protected]:[email protected]
  • 7/30/2019 114101403 Network Programming Week One Orientation

    3/20

    Administrative issues (2)

    Grading: is done based on tasks, vivas, demos, presentations, homeworks, reading assignments.

    Exam/ concept test conducted, scores are reflected in final grade.

    The deadline for any assignment can be extended with a 10%penalty per day.

    Deliverables are not accepted if the scheduled week is over.

    Collaboration and plagiarism

    Students are encouraged to talk to each other, to the TA, to thementor or to any one else about assignment. Any assistancethough must be limited to discussions. Student must write/code

    his/her own work. Detailed plagiarism policy is available in Logistics page.

  • 7/30/2019 114101403 Network Programming Week One Orientation

    4/20

    Why network programming?

    Discipline of designing and implementing

    network programs.

    Single program can communicate with

    other computers on network.

    Add power to simple programs.

    How to program in network?

  • 7/30/2019 114101403 Network Programming Week One Orientation

    5/20

  • 7/30/2019 114101403 Network Programming Week One Orientation

    6/20

    What is a socket?

    End point, of a bidirectional inter processcommunication flow across internet protocolbased computer network.

    Interface between an application and transportlayer.

    Socket address is a combination: IP address

    Port Protocol (?)

    Stream sockets & Datagram sockets

    SOCK_STREAM , SOCK_DGRAM.

  • 7/30/2019 114101403 Network Programming Week One Orientation

    7/20

    How to create a socket?

    Using socket function:

    int socket(int domain, int type, int protocol);

    Example: int sockfd;

    Sockfd = socket(AF_INET, SOCK_STREAM,0);

    If protocol is set to 0, then we let socket decide what protocol to usedepending on type.

    Socket function returns socket descriptor, if an error then returns -1.

  • 7/30/2019 114101403 Network Programming Week One Orientation

    8/20

  • 7/30/2019 114101403 Network Programming Week One Orientation

    9/20

    Socket Structures

    What is the size of IPv4 network address?

    32 bit

  • 7/30/2019 114101403 Network Programming Week One Orientation

    10/20

    Byte Order

    Functions to convert from host to network byte order and vice versa.

    htonl, htons, ntohl, ntohs

    Humans vs. sockets? Convert internet address to socketaddress or ascii. inet_aton or inet_ntoa

  • 7/30/2019 114101403 Network Programming Week One Orientation

    11/20

    TCP Socket

    Assign local

    port address

    to socket.

    Used by client to

    connect withserver.

    int listen(sockfd,

    int backlog);

    Maximum no of

    connections to

    queue for socket.

    Listens or waits for

    connect requests. Accept

    incoming requests

    directed to this socket.

  • 7/30/2019 114101403 Network Programming Week One Orientation

    12/20

    SocketAPI

  • 7/30/2019 114101403 Network Programming Week One Orientation

    13/20

    Socket Programming

    1. socket2. bind

    3. connect

    4. listen

    5. accept

    6. send,recv7. sendto, recvfrom

    8. close, shutdown

    9. getpeername

    10. gethostname

  • 7/30/2019 114101403 Network Programming Week One Orientation

    14/20

    UDP Socket

  • 7/30/2019 114101403 Network Programming Week One Orientation

    15/20

    Concurrency

    Ability to handle more than one client at a time.

    Use inherent operating system multi tasking capabilities.

  • 7/30/2019 114101403 Network Programming Week One Orientation

    16/20

  • 7/30/2019 114101403 Network Programming Week One Orientation

    17/20

  • 7/30/2019 114101403 Network Programming Week One Orientation

    18/20

    fork

  • 7/30/2019 114101403 Network Programming Week One Orientation

    19/20

    What is port?

    What is socket?

  • 7/30/2019 114101403 Network Programming Week One Orientation

    20/20

    Thank you