Repository navigation
Client
Iva edited this page Sep 27, 2024
·
3 revisions
Converts each character of the string into binary and sends corresponding signals to the server:
This function sends the message bit by bit usingSIGUSR1for 1s andSIGUSR2for 0s.
| Library |
<signal.h>, <unistd.h>
|
|---|---|
| Signature | void encoder(int pid, char *str); |
| Parameters |
pid: The process ID of the server. |
str: The string to be sent to the server. |
|
| Return | None |
int pid = 12345; // Example server PID
encoder(pid, "Hello"); // Sends the string "Hello" to the server, one bit at a time.
- Loops through each character in the string and converts it to binary.
- Sends each bit of the character to the server using
SIGUSR1for 1 andSIGUSR2for 0.usleep(200)is used to ensure the signals are sent with a slight delay to allow proper communication.
Validates the number of arguments provided to the client program:
Checks if the client program has received the correct number of arguments, specifically the server PID and the message to send.
| Library | None |
|---|---|
| Signature | bool ckargs(int ac); |
| Parameters |
ac: The argument count passed to the client. |
| Return |
true if the argument count is correct, otherwise false. |
int ac = 3;
if (ckargs(ac)) {
// Proceed with sending the message
}
- Ensures that exactly 3 arguments are passed: the client executable, the server PID, and the message.
- If the argument count is incorrect, it prints an error message and returns
false.
Previous ⬅️ • Top ⬆️ • Next ➡️