Socket Creation and Basic Configuration Flashcards
constructor of socket library
socket(family, type, proto, fileno)
What does the family field specify?
address family, which format is used to identify the socket address
AF_INET: address family _ internet ==> for ipv4
socket address is (host, port)
host could be hostname or ipv4
hostname first result of DNS resolution is used
IPv6 Internet protocols
AF_INET6
designed for efficient communication between processes in the same
UNIX machine
AF_UNIX
low-level raw packet that communicates with device drivers, i.e., at
the Data Link layer (TCP/IP Layer 2)
AF_PACKET
for communication using several Bluetooth protocols.
AF_BLUETOOTH
Reliable Datagram Socket (RDS) protocol. (Connectionless reliable
low-latency protocol)
AF_RDS
Controller Area Network Automotive bus protocol (developed by
Volkswagen for Linux)
AF_CAN
What does the type argument define
the type of the stream, how the socket stream will be handled
type of the transport layer protocol
TCP Protocol: Provides connection based, reliable and
sequenced communication
SOCK_STREAM
UDP Protocol: Provides datagram based (connectionless),
unreliable and non-sequenced communication
SOCK_DGRAM
Allows for customized lower-level programming2
SOCK_RAW
Datagram based, reliable and non-sequenced communication
SOCK_RDM
Datagram based, reliable and sequenced communication
SOCK_SEQPACKET
socket(AF_INET,RAW_SOCKET,…)
vs.
socket(AF_PACKET,RAW_SOCKET,…)
allows you to program at the IP layer
allows you to program at the Data Link layer.
what does proto = 0 indicate
underlying Layer 3 protocol. For the vast majority of applications, it is set to 0 which
indicates using the IP protocol.
when do we benefit from the fileno argument
This can be useful to close a
detached socket, and in some operations in the non-blocking mode.
s = socket() which will create
Pv4 TCP socket.
The address family, stream type and protocol are defined aaaaas?
attributes
s.family
s.proto
s.type
Once a socket is created, you cannot set/change the above three attributes, because they
are defined as read-only attributes.
You can get a list of all object
attributes and methods using the command
dir(<socket_object>)</socket_object>
does the __dict__ attribute exist? why?
no, none of the attributes are writable
because every class in Python extends the basic object class, the basic attributes
are also applicable like:
__module__
__class__
To verify socket creation, if s is a socket object type the command
type(s)
a socket is no
more than a file created by the OS, and a socket descriptor is treated just like any other
file descriptor
UNIX, Windows behaves a bit differently