0% found this document useful (0 votes)
4 views6 pages

Unit4 Network Programming Questions

The document covers Out-of-Band (OOB) data in socket programming, explaining its definition, characteristics, usage, advantages, and limitations. It also discusses the Internet Super Server (inetd/xinetd), detailing its functionality, current use, and efficiency in managing network services. Additionally, it outlines the general syntactic characteristics of PHP, including code tags, case sensitivity, and control structures such as conditional and looping statements.

Uploaded by

gjhansi2526
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Unit4 Network Programming Questions

The document covers Out-of-Band (OOB) data in socket programming, explaining its definition, characteristics, usage, advantages, and limitations. It also discusses the Internet Super Server (inetd/xinetd), detailing its functionality, current use, and efficiency in managing network services. Additionally, it outlines the general syntactic characteristics of PHP, including code tags, case sensitivity, and control structures such as conditional and looping statements.

Uploaded by

gjhansi2526
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Out-of-Band (OOB) Data in Socket Programming

Definition:
Out-of-Band (OOB) data in sockets refers to urgent data that a sender transmits separately
from the normal stream of data in TCP connections. It allows high-priority information to be
delivered without waiting for the regular data flow.

Characteristics:
- Works only on TCP (SOCK_STREAM) sockets.
- Uses the Urgent Pointer field in the TCP header.
- At most 1 byte of urgent data is guaranteed at a time.
- OOB data is not truly outside the stream, but it is marked as urgent.

Usage:
Sending OOB data:
send(sockfd, &data, 1, MSG_OOB);
- sockfd: The socket file descriptor created by socket() and connected via connect() or
accept().
- &data: Address of the variable holding the urgent data byte.
- 1: Number of bytes being sent (OOB in TCP supports 1 urgent byte).
- MSG_OOB: A flag indicating that this data should be sent as Out-of-Band (urgent) data.

Receiving OOB data:


recv(sockfd, buffer, size, MSG_OOB);
- sockfd: The socket file descriptor (already created and connected).
- buffer: Memory area where the received data will be stored.
- size: Maximum number of bytes to read into buffer.
- MSG_OOB: Special flag telling the kernel to read Out-of-Band (OOB) (urgent) data instead
of normal in-band data.

Advantages:
- Provides urgent signaling without a separate connection.
- Ensures priority delivery of critical data.

Limitations:
- Only one byte of urgent data is supported at a time.
- Behavior may differ across operating systems.
- Rarely used in modern applications.
- Not supported in UDP.

Related Socket Options / Calls:


- send() with MSG_OOB → send urgent data.
- recv() with MSG_OOB → receive urgent data.
- select() → detect OOB arrival using exceptfds.
- SO_OOBINLINE → deliver OOB inline with normal data.

Internet Super Server (inetd/xinetd)

Definition:
The Internet Super Server is a daemon (background service) that manages multiple
network services. Instead of keeping each service (like FTP, Telnet, or POP3) running
continuously, inetd or xinetd listens on multiple ports and starts the required service only
when a client connects.

How It Works:
1. inetd (or xinetd) starts during system boot.
2. It reads its configuration files such as /etc/[Link] or /etc/xinetd.d/.
3. It listens on specific ports defined in those files.
4. When a client request arrives (e.g., FTP on port 21):
- It accepts the connection.
- Starts the appropriate service program (e.g., ftpd, telnetd).
- Hands over the socket to that program.
- Waits for the next incoming request.

Current Use:
- inetd is mostly obsolete.
- xinetd can still be installed using: sudo apt install xinetd
- To check listening services: ss -tulpn or ss -ulnp

Options Explanation:
- -t → Shows TCP ports
- -u → Shows UDP ports
- -l → Shows listening sockets
- -p → Displays process information
- -n → Displays numeric ports

Comparison with I/O Multiplexing:


- I/O Multiplexing is a programming technique using system calls like select(), poll(), or
epoll() for handling multiple I/O streams in one process.
- The Internet Super Server is a daemon used at the system level to manage multiple
lightweight services efficiently.
Efficiency:
- Saves memory and CPU by not running idle daemons.
- Starts services on demand.
- Ideal for low-traffic services like Telnet, FTP, or TFTP.

In summary, inetd/xinetd acts as a centralized network service manager that starts and
stops services dynamically, ensuring efficient resource utilization.

General Syntactic Characteristics of PHP

1. PHP Code Tags:


PHP code is always written inside special tags:
<?php
// PHP code here
?>
This allows PHP to be embedded within HTML pages.

2. Case Sensitivity:
- Variables are case-sensitive.
- Function names, keywords, and class names are not case-sensitive.

3. Statements End with Semicolons:


Each PHP statement must end with a semicolon.
Example:
$x = 10;
$y = 20;
echo $x + $y;

4. Comments:
PHP supports three types of comments:
- // for single line
- # for single line
- /* ... */ for multi-line

5. Variables:
- Begin with the $ symbol.
- Must start with a letter or underscore.
Example:
$name = "PHP";
$age = 25;
6. Data Types:
PHP is loosely typed, meaning you don’t declare variable types explicitly. Common data
types include:
String, Integer, Float, Boolean, Array, Object, and NULL.

Example:
$x = 10; // Integer
$y = 10.5; // Float
$name = "Jhansi"; // String
$isActive = true; // Boolean

7. Operators:
PHP provides several types of operators:
- Arithmetic operators: +, -, *, /, %, **
- Comparison operators: ==, !=, ===, >, <, >=, <=
- Logical operators: &&, ||, !
- Assignment operators: =, +=, -=, *=, /=
Operators are used to perform operations like arithmetic calculations, comparisons, and
logic-based decisions in PHP programs.

Control Structures in PHP

Control structures determine how the flow of execution proceeds in a PHP program. They
include conditional and looping statements.

1. Conditional Statements:
Used to execute different code blocks based on conditions.

(a) if Statement:
if ($x > 10) {
echo "Big";
}

(b) if...else Statement:


if ($x > 10) {
echo "Big";
} else {
echo "Small";
}

(c) if...elseif...else Statement:


if ($x > 10) {
echo "Greater";
} elseif ($x == 10) {
echo "Equal";
} else {
echo "Smaller";
}

(d) switch Statement:


$day = "Monday";
switch ($day) {
case "Monday":
echo "Start of the week";
break;
case "Friday":
echo "Weekend is near";
break;
default:
echo "Normal day";
}

2. Looping Statements:
Used for repeating code execution.

(a) for Loop:


for ($i = 1; $i <= 5; $i++) {
echo $i . " ";
}

(b) while Loop:


$i = 1;
while ($i <= 5) {
echo $i . " ";
$i++;
}

(c) do...while Loop:


$i = 1;
do {
echo $i . " ";
$i++;
} while ($i <= 5);
(d) foreach Loop:
$colors = array("red", "green", "blue");
foreach ($colors as $c) {
echo $c . " ";
}

3. Jump Statements:
Used to alter the normal flow of control.
- break: exits the current loop or switch.
- continue: skips the rest of the current iteration.
- exit(): terminates script execution.

Example:
for ($i = 1; $i <= 5; $i++) {
if ($i == 3) continue;
echo $i . " ";
}

Summary:
- Conditional structures: if, else, elseif, switch.
- Looping structures: for, while, do...while, foreach.
- Jump structures: break, continue, exit().

You might also like