Skip to main content

Client Usage

The client requires exactly two arguments:
./client <PID> <message>
  • <PID> - The server’s process ID (must be numeric)
  • <message> - The string to send (must be non-empty)

Basic Examples

./client 12345 "Hello, World!"
Quotes are required when your message contains spaces or special characters.

Complete Example

1

Start the server in one terminal

$ ./server
SUCCESS!, Server is ready :D! The PID: 54321
Waiting fot the string...
Note the PID displayed: 54321
2

Send a message from another terminal

$ ./client 54321 "Hello from client!"
The client exits silently on success.
3

Check server output

Back in the server terminal, you’ll see:
$ ./server
SUCCESS!, Server is ready :D! The PID: 54321
Waiting fot the string...
Hello from client!
The message appears character by character as it’s received.

Multiple Messages

You can send multiple messages to the same server:
$ ./server
SUCCESS!, Server is ready :D! The PID: 54321
Waiting fot the string...
First message
Second message
Message #3
Messages are not separated by newlines or delimiters. They will appear concatenated on the server unless your message includes \n.

How It Works

The client sends messages by converting each character into binary and transmitting it bit-by-bit using UNIX signals:
1

Validate arguments

The client checks for correct usage:
if (argc != 3 || !argv[2])
    return (ft_printf("Usage : ./client <PID> <string to send>\n"), 1);
2

Validate PID format

The PID must contain only digits:
while (argv[1][j] != '\0')
{
    if (argv[1][j] < '0' || argv[1][j] > '9')
    {
        ft_printf("Wrong PID\n");
        return (1);
    }
    j++;
}
3

Send message bit-by-bit

For each character, the client sends 8 bits:
bits = 8;
while (--bits >= 0)
{
    if ((str[i] >> bits) & 1)
    {
        if (kill(pid, SIGUSR2) == -1)
            return (1);
    }
    else
    {
        if (kill(pid, SIGUSR1) == -1)
            return (1);
    }
    usleep(700);
}
  • Bit 1 → Send SIGUSR2
  • Bit 0 → Send SIGUSR1
  • 700 microseconds delay between each bit

Timing Details

The client includes a 700 microsecond delay between each bit:
usleep(700);
Why? This delay ensures:
  • The server has time to process each signal
  • Signals don’t get lost or merged
  • Reliable character reconstruction
Message transmission time:
  • Each character = 8 bits
  • Each bit = 700 microseconds
  • One character ≈ 5.6 milliseconds
  • “Hello” (5 chars) ≈ 28 milliseconds

Error Messages

$ ./client
Usage : ./client <PID> <string to send>
Cause: Missing argumentsSolution: Provide both PID and message:
./client 12345 "Your message"
$ ./client 12345
Usage : ./client <PID> <string to send>
Cause: Missing message argumentSolution: Add a message:
./client 12345 "Hello"
$ ./client abc123 "Hello"
Wrong PID
Cause: PID contains non-numeric charactersSolution: Use only numbers:
./client 12345 "Hello"
$ ./client 99999 "Hello"
Client failed sending signal
Cause: The kill() system call failed. Common reasons:
  • Server PID doesn’t exist
  • Server process has terminated
  • Permission denied (trying to signal another user’s process)
Solution:
  1. Verify the server is running: ps aux | grep server
  2. Check the correct PID from server output
  3. Restart the server if needed

Real-World Examples

./client 12345 " _____\n|  H  |\n|_____|" 

Client Behavior

Silent Success

The client exits without output when the message is sent successfully. Check the server terminal to see the received message.

No Confirmation

The client doesn’t wait for server acknowledgment. It assumes success if kill() returns 0.

Bit-by-Bit

Messages are sent one bit at a time, starting from the most significant bit (MSB) of each character.

Fixed Delay

700 microseconds between each bit transmission ensures reliable delivery.

Testing Different Scenarios

Send multiple messages quickly:
./client 12345 "A" && ./client 12345 "B" && ./client 12345 "C"
Server sees: ABC (messages concatenated)

Troubleshooting

Check:
  1. Server is running: pgrep server
  2. Using correct PID: Check server startup message
  3. Client exited without error message
  4. Server terminal is visible and active
Try:
# Verify server PID
ps aux | grep "./server"

# Send test message
./client <ACTUAL_PID> "test"
Possible causes:
  1. Multiple clients sending simultaneously
  2. System under heavy load (signals delayed)
  3. Server was killed mid-transmission
Solution:
  • Send messages one at a time
  • Increase the delay in client.c (change usleep(700) to higher value)
  • Ensure stable system performance
The 700 microsecond delay is per bit:
  • 1 character = 8 bits × 700μs = 5.6ms
  • 100 characters = ~560ms
This is expected behavior. For very long messages, consider:
  • Sending in smaller chunks
  • Reducing the delay (may reduce reliability)

Build docs developers (and LLMs) love