Address Structure - Advanced Unix Programming - Lecture Slides, Slides of Computer Programming

Some concept of Advanced Unix Programming are Address Structure, Basic Thread Functions, Client-Server Design, Network Programming, Signals and Thread, Thread-Specific Data, Unix File System, Reliable Communication. Main points of this lecture are: Address Structure, Socket Address Structure, Byte Ordering, Manipulation Functions, Concurrent Server, Client-Server Design, Socket Address Structure, Ordering and Manipulation, Functions, Accept

Typology: Slides

2012/2013

Uploaded on 04/29/2013

parmita
parmita 🇮🇳

4.7

(17)

183 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Week 7 Topics
Basic TCP sockets
Socket address structure
Byte ordering and manipulation functions
socket, connect, bind, listen, accept
Client-Server design
Concurrent server
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Address Structure - Advanced Unix Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

Week 7 Topics

• Basic TCP sockets

– Socket address structure

– Byte ordering and manipulation functions

– socket, connect, bind, listen, accept

• Client-Server design

• Concurrent server

Basic TCP sockets

• Socket address structure

• Byte ordering and manipulation functions

• socket, connect, bind, listen, accept

connect

  • #include <sys/socket.h>

int connect(int sockfd, const struct sockaddr

*servaddr, socklen_t addrlen);

  • servaddr : socket address structure (IP address and port)
  • connect actively starts the TCP connection

establishment phase

  • Possible errors
    • ECONNREFUSED
    • EHOSTUNREACH
    • ETIMEDOUT
    • Etc
  • Close the socket after error

bind

  • #include <sys/socket.h>

int bind(int sockfd, const struct sockaddr &myaddr,

socklen_t addlen);

  • myaddr contains its own address

Address port result

INADDR_ANY 0 system selects addr and port

INADDR_ANY !=0 system selects addr, user selects

port

Local IP address 0 user selects addr, system selects

port

Local IP address !=0 user selects both addr and port

  • Client does not have to bind , system assigns a port
  • See example2.c

accept

  • Blocking by default

#include <sys/socket.h> int accept (int sockfd, struct sockaddr *cliaddr, socklen_t *addrlen);

  • Creates a new socket and returns a file descriptor

associated with that socket

  • Gives client’s address in cliaddr
  • See example2.c