Skip to content
Iva edited this page Sep 27, 2024 · 3 revisions

encoder

Converts each character of the string into binary and sends corresponding signals to the server:
This function sends the message bit by bit using SIGUSR1 for 1s and SIGUSR2 for 0s.

Original Function:

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

Usage Example:

int pid = 12345; // Example server PID
encoder(pid, "Hello"); // Sends the string "Hello" to the server, one bit at a time.

Specifics:

  • Loops through each character in the string and converts it to binary.
  • Sends each bit of the character to the server using SIGUSR1 for 1 and SIGUSR2 for 0.
  • usleep(200) is used to ensure the signals are sent with a slight delay to allow proper communication.

ckargs

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.

Original Function:

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.

Usage Example:

int ac = 3;
if (ckargs(ac)) {
    // Proceed with sending the message
}

Specifics:

  • 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 ➡️

Clone this wiki locally