GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Mindmap

Sockets

Jason Espinoza Siles Spanisch

Inhalt der Mindmap

Sockets

  1. Tecnológico de Costa Rica, Carrera: Ingeniería en Computación, Sede: Cartago, Curso: Principios de sistemas operativos, Profesor: Esteban Arias Méndez, Estudiante: Jason David Espinoza Siles, Carné: 201223941, II semestre, 2016, Libro: Begining Linux Programming: capítulo 15. Reporte #8

  2. What Is a Socket?

    • A socket is a communication mechanism that allows client/server systems to be developed either locally, on a single machine, or across networks. Linux functions such as printing, connecting to databases, and serving web pages as well as network utilities such as rlogin for remote login and ftp for file transfer usually use sockets to communicate.
    • Sockets are created and used differently from pipes because they make a clear distinction between client and server. The socket mechanism can implement multiple clients attached to a single server.
  3. Socket Connections

    • First, a server application creates a socket, which like a file descriptor is a resource assigned to the server process and that process alone. The server creates it using the system call socket , and it can’t be shared with other processes. Next, the server process gives the socket a name. Local sockets are given a filename in the Linux file sys- tem, often to be found in /tmp or /usr/tmp . For network sockets, the filename will be a service identi- fier (port number/access point) relevant to the particular network to which the clients can connect. This identifier allows Linux to route incoming connections specifying a particular port number to the correct server process. For example, a web server typically creates a socket on port 80, an identifier reserved for the purpose. Web browsers know to use port 80 for their HTTP connections to web sites the user wants to read. A socket is named using the system call bind . The server process then waits for a client to connect to the named
  4. Socket Attributes

    • Sockets are characterized by three attributes: domain, type, and protocol. They also have an address used as their name. The formats of the addresses vary depending on the domain, also known as the protocol family. Each protocol family can use one or more address families to define the address format.
    • Socket Domains
      • Domains specify the network medium that the socket communication will use
      • Socket Types
        • Stream sockets (in some ways similar to standard input/output streams) provide a connection that is a sequenced and reliable two-way byte stream. Thus, data sent is guaranteed not to be lost, duplicated, or reordered without an indication that an error has occurred. Large messages are fragmented, transmitted, and reassembled. This is similar to a file stream, which also accepts large amounts of data and splits it up for writing to the low-level disk in smaller blocks. Stream sockets have predictable behavior.
      • Datagram Sockets
        • In contrast, a datagram socket, specified by the type SOCK_DGRAM , doesn’t establish and maintain a con- nection. There is also a limit on the size of a datagram that can be sent. It’s transmitted as a single network message that may get lost, duplicated, or arrive out of sequence — ahead of datagrams sent after it.
      • Socket Addresses
        • Each socket domain requires its own address format. For an AF_UNIX socket, the address is described by a structure, sockaddr_un , defined in the sys/un.h include file.
    • Socket Protocols
      • Where the underlying transport mechanism allows for more than one protocol to provide the requested socket type, you can select a specific protocol for a socket. In this chapter, we concentrate on UNIX net- work and file system sockets, which don’t require you to choose a protocol other than the default.
  5. Creating a Socket

    • The socket created is one end point of a communication channel. The domain parameter specifies the address family, the type parameter specifies the type of communication to be used with this socket, and protocol specifies the protocol to be employed.
  6. Naming a Socket

    • To make a socket (as created by a call to socket ) available for use by other processes, a server program needs to give the socket a name. Thus, AF_UNIX sockets are associated with a file system pathname, as you saw in the server1 example. AF_INET sockets are associated with an IP port number.
  7. Creating a Socket Queue

    • To accept incoming connections on a socket, a server program must create a queue to store pending requests. It does this using the listen system call.
  8. Accepting Connections

    • Once a server program has created and named a socket, it can wait for connections to be made to the socket by using the accept system call.
  9. Requesting Connections

    • Client programs connect to servers by establishing a connection between an unnamed socket and the server listen socket. They do this by calling connect .
  10. Closing a Socket

    • You can terminate a socket connection at the server and client by calling close , just as you would for low- level file descriptors. You should always close the socket at both ends.
  11. Host and Network Byte Ordering

    • When we run these versions of the server and client programs on an Intel processor–based Linux machine, we can see the network connections by using the netstat command. This command will also be available on most UNIX systems configured for networking. It shows the client/server connection waiting to close down. The connection closes down after a small timeout. (Again, the exact output may vary among different versions of Linux.)
  12. Networ k Information

    • Similarly, given a computer’s name, you can determine the IP address by calling host database functions that resolve addresses for you. They do this by consulting network configuration files, such as /etc/hosts , or network information services, such as NIS (Network Information Services, formerly known as Yellow Pages) and DNS (Domain Name Service).
  13. The Internet Daemon (xinetd/inetd)

    • The Internet daemon is implemented in modern Linux systems by xinetd . This implementation has replaced the original UNIX program, inetd , although you will still see inetd in older Linux systems and on other UNIX-like systems.
  14. Socket Options

    • The setsockopt function is used to manipulate options
  15. Multiple Clients

    • ou might need to consider the case of multiple, simultaneous clients connecting to a server. You’ve seen that when a server program accepts a new connection from a client, a new socket is created and the original listen socket remains available for further connections. If the server doesn’t immediately accept further con- nections, they will be held pending in a queue. The fact that the original socket is still available and that sockets behave as file descriptors gives you a method of serving multiple clients at the same time. If the server calls fork to create a second copy of itself, the open socket will be inherited by the new child process. It can then communicate with the con- necting client while the main server continues to accept further client connections.
    • Your simple server program can benefit by using select to handle multiple clients simultaneously, without resorting to child processes. For real applications using this technique, you must take care that you do not make other clients wait too long while you deal with the first to connect.
  16. Datagrams

    • Services provided by UDP are typically used where a client needs to make a short query of a server and expects a single short response. If the cost in terms of processing time is low enough, the server is able to provide this service by dealing with requests from clients one at a time, allowing the operating system to hold incoming requests in a queue. This simplifies the coding of the server. Because UDP is not a guaranteed service, however, you may find that your datagram or your response goes missing. So if the data is important to you, you would need to code your UDP clients carefully to check for errors and retry if necessary. In practice, on a local area network, UDP datagrams are very reliable.

Informationen

Beschreibung
Mindmap am Sockets, erstellt von Jason Espinoza Siles am 05/10/2016.
Aufrufe
1
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck