Presentation is loading. Please wait.

Presentation is loading. Please wait.

Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.

Similar presentations


Presentation on theme: "Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use."— Presentation transcript:

1 Socket Addresses

2 Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use –used to debug internally

3 Protocol families SNA - IBM Systems Network Architecture UUCP - Unix to Unix copy XNS - Xerox Network System NETBIOS - IBM Basic I/O system TCP/IP ( PF_INET ) UNIX ( PF_UNIX )

4 Constants for addresses PF_UNIX1 PF_INET2 PF_NS6 (xns) PF_SNA11 PF_DECnet12 PF_APPLETALK16 PF_X2520 …...

5 Address Formation All Protocols do not agree Socket Abstraction TCP/IP IP Address Protocol Port Unix socket Other Protocols Address format may be different Built to support multiple protocols

6 Address Families Socket abstraction has a series of address families so that each family can have it’s own format for endpoint addresses. TCP/IP has address family named AF_INET TCP/IP also has a protocol family : PF_INET Both have numeric value 2 which leads to further confusion.. They can be switched at will with no apparent consequence.

7 Generic Address (address family, endpoint address in family) socket API defines one to use as a general address, but it won’t work for everything Works for TCP/IP not Unix struct sockaddr { u_short sa_family; char sa_data[14]; }; E.g. Unix sockets (internal) use a named pipe for the endpoint and the length of it is comparable to a path/file name (much longer)

8 What TCP/IP uses for an address 2 byte address family (AF_INET) 2 byte port number 4 byte IP address 8 bytes unused struct sock_addr_in{ u_short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8] } TCP/IP apps need not use sockaddr Use sockaddr_in

9 Procedures in API

10 socket () Purpose: create a socket for communications Returns: descriptor for a new socket Arguments: –protocol family PF_INET –type of service stream (TCP) datagram (UDP)

11 connect() Purpose: establish the connection Returns: success/failure Arguments: –remote endpoint

12 send() Purpose: send data through to other end Returns: success/failure Arguments: –socket descriptor –address –length of data –control directives

13 recv() Purpose: get response Returns: message received Arguments: –socket descriptor –address of buffer –length of buffer –control bits NOTE - recv is limited to buffer space and will cut off if necessary. Must go back

14 recv() (UDP) Works similarly If too much data: – truncated at the size of the receive buffer –discard remainder –return error condition

15 closesocket() Purpose: give socket resource back to OS if shared with other processes, reference count decremented (until 0). Returns: message received Arguments: –socket descriptor –address of buffer –length of buffer –control bits

16 bind() Purpose: specify local endpoint address Returns: message received Arguments: –socket descriptor –endpoint address ( sockaddr_in for TCP/IP) IP address port

17 listen() Purpose: put socket in passive mode and specify size of queue for incoming requests Returns: success/fail Arguments: –socket descriptor –size of queue

18 accept() Purpose: wait for next incoming request Returns: new socket for interaction Arguments: –socket descriptor

19 Windows client-server usage CLIENT WSAStartup socket connect send recv closesocket WSACleanUP SERVER WSAStartup socket bind listen accept recv send closesocket WSACleanup


Download ppt "Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use."

Similar presentations


Ads by Google