Download presentation
Presentation is loading. Please wait.
Published byBarry Terry Modified over 9 years ago
1
Fall 2000Datacom 11 Lecture 4 Socket Interface Programming: Service Interface between Applications and TCP
2
Fall 2000Datacom 12 Inter-Process Communication Turn host-to-host connectivity into process-to-process communication.. Host Application Host Application Host Channel
3
Fall 2000Datacom 13 Layering Use abstractions to hide complexity Abstraction naturally lead to layering
4
Fall 2000Datacom 14 Layering Request/reply channel Message stream channel Application programs Hardware Host-to-host connectivity Alternative abstractions at each layer
5
Fall 2000Datacom 15 Internet Architecture Defined by Internet Engineering Task Force (IETF) Hourglass Design Application vs Application Protocol (FTP, HTTP) … FTPHTTPNV TFTP TCP UDP IP NET 1 2 n
6
Fall 2000Datacom 16 ISO or OSI Architecture OSI= Open Systems Interconnection Application Presentation Session Transport End host One or more nodes within the network Network Data link Physical Network Data link Physical Network Data link Physical Application Presentation Session Transport End host Network Data link Physical
7
Fall 2000Datacom 17 3-features of Internet Architecture Strict layering is abandoned IP is the big idea—a single protocol for interconnecting networks and providing host-to- host connectivity To become a standard requires a working implementation
8
Fall 2000Datacom 18 Protocols Building blocks of a network architecture Provides communications service that higher level objects use to exchange messages Each protocol object has two different interfaces –service interface: operations on this protocol –peer-to-peer interface: messages exchanged with peer
9
Fall 2000Datacom 19 Host 1 Protocol Host 2 Protocol High-level object High-level object Service interface Peer-to-peer interface Interfaces
10
Fall 2000Datacom 110 Socket Interface-an Application Programming Interface (API) Create the Socket for a specific transport layer protocol int socket(int domain,int type, int protocol) domain=Protocol Family=PF_INET type=semantics=SOCK_STREAM (or DGRAM) protocol=0 (UNSPEC) PF_INET and SOCK_STREAM means TCP socket returns an socket number: negative value means an error
11
Fall 2000Datacom 111 Socket Interface: Client (a) Connecting to a Socket int connect (int socket, struct sockaddr*address, int addr_len) –sockaddr is the name of a data structure that gives the IP address for reaching the server’s socket variable_name.element1 is address family=AF_INET variable_name (sin).element2 is server IP address variable_name.element3 is address family=Port number (use htons function to translate) –address is a pointer to location of address information (&sin) –addr_len is the length of the address field to which address points
12
Fall 2000Datacom 112 Socket Interface: Client (b) Sending data to a Socket int send(int socket, char*message, int msg_len, int flags) –message is a pointer to the location of the message to be sent –msg_len is the length of that memory location
13
Fall 2000Datacom 113 Socket Interface: Server (a) Binding a Socket to an IP address int bind (int socket, struct sockaddr*address, int addr_len) –sockaddr is the name of a data structure that gives the IP address for receiving information socket Variable_name.element1 is address family=AF_INET Variable_name.element2 is client IP address=UNSPEC until connected Variable_name.element3 is address family=Port number (use htons function to translate)
14
Fall 2000Datacom 114 Socket Interface: Server (b) Defining the queue length for the receiving socket int send(int socket, int backlog) –backlog is number of calls waiting Passive listening int accept (int socket, struct sockaddr*address, int addr_len) –Sender’s IP address is returned –New Socket is created and its number is returned
15
Fall 2000Datacom 115 Socket Interface: Server (c) Receiving a message int recv(int socket, char*buffer, int buf_len, int flags) –new socket created by accept function –buffer is a pointer to the location where message will be stored –buf_len is the length of that memory location Closing a socket close(socket) Use this command to close the new_socket created when the connection is accepted. The old one is still listening—keeping track of the incoming queue
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.