-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
69 lines (58 loc) · 1.88 KB
/
client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hecmarti <hecmarti@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 16:06:34 by hecmarti #+# #+# */
/* Updated: 2024/05/26 10:39:06 by hecmarti ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
// Sends the specified message to the specified
// process using SIGUSR1 and SIGUSR2 signals
// Initialize variables
// Iterate through each character of the message
// Iterate through each bit of the current character
// If the current bit is 1, send SIGUSR1 signal;
// otherwise, send SIGUSR2 signal
// Sleep for 100 microseconds between each signal
void signal_action(int pid, char *str)
{
int i;
int c;
i = 0;
while (*str)
{
c = *(str);
while (i < 8)
{
if (c << i & 0b10000000)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
i++;
usleep(100);
}
str++;
i = 0;
}
}
// Validate the number of arguments
// Convert the server ID (PID) to an integer and
// send the message using the signal_action function
int main(int argc, char **argv)
{
if (argc != 3)
{
ft_printf("Invalid number of arguments.\n");
ft_printf("Format: [./client <SERVER ID (PID)> <STRING>]\n");
exit(EXIT_FAILURE);
}
else
{
signal_action(ft_atoi(argv[1]), argv[2]);
}
return (0);
}