LU7 Socket Programming Flashcards

1
Q

What is the primary purpose of socket programming?

A

To enable IPC, especially across a network in a distributed system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In a networked environment, what architectural model is commonly used with sockets?

A

Client-server model

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Briefly describe the role of the ‘client’ in a client-server socket communication.

A

Initiates a connection to the server and requests services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the role of the ‘server’ in the client-server model.

A

Listens for incoming connections, accepts requests, and provides services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s the purpose of fork()?

A

Creating child process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do processes communicate between parent and child after a fork()?

A

[ SPMs ]

Using IPC mechanisms:

  • signal
  • pipes
  • message queues
  • shared memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In a networked program using sockets, what medium enables communication between client and server?

A

A network (e.g., LAN, WAN).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What defines the rules for communication between sockets?

A

Protocols (e.g., TCP/IP).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are sockets?

A

The traditional UNIX IPC mechanism that allows processes to communicate, even if they’re on different machines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Name a few common uses of sockets?

A

transferring data/video/voice/files from one machine to another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Name two types of connections.

A

Connection-oriented, Connectionless

Connection-oriented communication (like TCP) establishes a dedicated, reliable connection with ordered delivery.
Connectionless communication (like UDP) sends data independently without guarantees of order or delivery.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the key characteristics of Connection oriented model?

A
  • dedicated connection
  • reliable packet transfer
  • packet will send and receive in order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the key characteristics of Connectionless oriented model?

A
  • Data packets routed individually
  • No guarantee of delivery, order, or data integrity, speed prioritized
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Name a common protocol used for connection oriented model.

A

TCP/IP
Transmission Control Protocol/Internet Protocol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Name a common protocol used for connectionless oriented model.

A

UDP
user datagram protocol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the disadvantage of Connection oriented model?

A

Requires more overhead due to the setup phase, slower compared to connectionless model

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the disadvantage of Connectionless oriented model?

A

Data packets may arrive out of order or be lost, less reliable than connection-oriented communication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

To establish any communication, client and server need to be connected at what level?

A

Hardware & Software level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are the few steps in a server?

A

[ CNSAS ]

  1. creating a server socket
  2. naming a server socket
  3. set the maximum number of pending connections
  4. accepting connections
  5. serving a client
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are the few steps in a client?

A

1 creating a client socket
2. connecting a client socket to the server socket
3. communicating via sockets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the format of IP address?

A

4 decimal numbers separated by dot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How UNIX system calls deal with IP address to be usable for later?

A

convert using inet_addr()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is a socket?

A

An interface between application and network

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What does the socket type dictates?

A

style of communication (reliable or best effort, connection-oriented or connectionless)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What are the two essential types of sockets?
* SOCK_STREAM: connection-oriented * SOCK_DGRAM: connectionless
26
SOCK_STREAM is also known as?
TCP
27
SOCK_DGRAM is also known as?
UDP
28
What is the characteristic of a SOCK_STREAM?
reliable delivery, in-order guaranteed, connection-oriented, bidirectional
29
What is the characteristic of a SOCK_DGRAM?
unreliable delivery, no order guarantees, no notion of “connection
30
What library does the socket address structure define in?
sys/socket.h
31
In socket, what are the address and port for?
* `address` = knowing which machine to communicate with * `port` = which channel/app to connect
32
What does the server do with the port?
Server listens for connection on a specified port number
33
How many ports does each host has?
65,536 (2^16)
34
35
What's the function of socket() system call?
To create a **comunication end point** (a socket) within a network
36
What are the parameters for socket()?
domain, int type, int protocol
37
What is network type `AF_INET` for?
AF = Address family INET = Internet internet domain
38
What is network type`AF_UNIX` for?
AF = Address Family within the same machine (local) Provide a way for programs running on the **same** computer (local) to communicate with each other.
39
What does SOCK_STREAM dictates?
for connection oriented
40
What does SOCK_DGRAM dictates?
for connectionless oriented
41
If SOCK_STREAM used, which protocol will it use?
TCP
42
If SOCK_DGRAM used, which protocol will it use?
UDP
43
What is bind() function used for?
It **associates** a socket with an IP and port, enabling the OS to **route** network traffic to the correct server application.
44
What are the parameters for bind()?
* `sockfd` * `struct sockaddr *address` * `size_t add_len`
45
What is listen() function used for?
Setup server to wait for connection
46
What are the parameters for listen()?
* `sockfd` * `int queue_size`
47
What does queue_size in listen() do?
set the *maximum* number of *pending connection* from the client.
48
What is accept() function used for?
When received connection request from client, server need to create a new second socket to handle the communication
49
What are the parameters for accept()?
sockfd, struct sockaddr *address, size_t *add_len
50
Why is add_len can be NULL in accept()
Due to the nature of connection oriented model, can be set to NULL
51
In order to request for a connection, what function do we need to use?
connect()
52
What are the parameters for connect()
csockfd, const struct sockaddr *address, size_t add_len
53
How do send and receive data between client and server?
recv(), send()
54
What are the parameters for recv()?
sockfd, void *buffer, size_t length, int flags
55
What are the parameters for send()?
sockfd, const void *buffer, size_t length, int flags
56
What does MSG_PEEK do?
look at data without actually receiving
57
What does MSG_OOB do?
receive out of band data like interrupt signal
58
When does MSG_WAITALL return?
return only when full amount of data is available
59
What does flags for sending MSG_OOB do?
send out of band data
60
What does flags for sending MSG_DONTROUTE do?
message is send via most direct route rather than quickest route
61
How to close the connection?
close(int sockfd)
62
If the type is SOCK_STREAM, what does close() do?
kernel will guarantee that all data sent to the socket will be sent to the receiving process and close() to be blocked until completion
63
If the type is SOCK_DGRAM, what does close() do?
Socket is closed immediately
64
If Inet_Addr fail, what will it return?
-1
65
When the type is SOCK_STREAM, which operations will occur on the server?
Socket->bind->listen->accept->read->write->close
66
When the type is SOCK_STREAM, which operations will occur on the **client**?
Socket->connect->send->recv->close
67
TCP is which of these choice, 1. Reliable 2. Unreliable 3. Connectionless 4. Connection-Oriented, Pick two?
Reliable and Connection-Oriented
68
UDP is which of these choice, 1. Reliable 2. Unreliable 3. Connectionless 4. Connection-Oriented, Pick two?
Unreliable and Connectionless
69
What happens if client doesn't close socket?
There is no defined outcome
70
Does client or server always closes first?
Either can close first
71
What is the purpose of the 'domain' argument in the `socket()` function, and what is the most common value used for internet-based communication?
Specifies the communication domain; AF_INET is the most common for internet.
72
Explain the key difference between TCP and UDP in terms of data delivery.
TCP guarantees reliable, ordered delivery; UDP does not.
73
What is the purpose of setting a maximum number of pending connections using the `listen()` function?
Limits the number of incoming connection requests the server will queue.
74
What information is filled into the `sockaddr` structure when the `accept()` function returns a new socket descriptor?
Client's address and port information.
75
Imagine you're using a 'SOCK_STREAM' socket to send data over a network connection. You call the `close()` function to close the socket. Why might this `close()` call take some time to finish, instead of returning immediately?
Because the kernel needs to ensure that all data is sent to the receiving process.
76
Why is network address conversion necessary when using UNIX networking system calls?
UNIX system calls can't directly use standard IP address format.
77
What is the purpose of `inet_addr()`?
Converts human-readable IP address to a numeric form.
78
What data type does `inet_addr()` return on success?
in_addr_t
79
What are the typical return values of the function accept()?
New socket identifier
80
In the context of networking, what is a 'port'?
A channel or endpoint used for communication between processes.
81
What is the valid range for port numbers, and which range is reserved for specific applications?
0-65535, 0-1023 are reserved.
82
Name a scenario where TCP (SOCK_STREAM) is preferable over UDP (SOCK_DGRAM).
When complete and accurate data transmission is critical (e.g., file transfer).
83
Explain the significance of the `sa_family` field within the `sockaddr` structure.
Specifies the address family (e.g., AF_INET for IPv4).
84
What are the arguments to socket function in the context of creating a TCP socket?
domain=AF_INET, type=SOCK_STREAM, protocol=0
85
What are the arguments to socket function in the context of creating a UDP socket?
domain=AF_INET, type=SOCK_DGRAM, protocol=0
86
True or False: A single server can handle only one client connection at a time.
False
87
True or False: UDP guarantees that packets will arrive in the order they were sent.
False
88
In a client-server interaction with sockets, what does it signify if connect() return -1?
Failed
89
What is the purpose of calling listen() on server side?
Sets up the queue for upcoming connection requests
90
If a server creates a socket for handling HTTP traffic, what port number would it commonly use?
80
91
When designing the server what happens after accepting
Need to create a new second socket to handle the connection
92
Is it possible for the client to know what is going to send
Yes
93
In connection oriented, what does it mean when connection has been achieved?
A stable connection is made and you can start communication!
94
When to close the connection?
After all the data has been transferred. It is advised to close the connection ASAP!
95
Does TCP perform Error Check?
Yes
96
What is the downside of UDP other than unreliable data?
No congestion control
97
What operations is the client side required to have if it wishes to connect to the server?
Socket and connect function calls are required