-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
51 lines (46 loc) · 1.43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rapcampo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 13:38:08 by rapcampo #+# #+# */
/* Updated: 2024/01/15 11:48:47 by rapcampo ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void send_bits(int pid, unsigned char c)
{
int i;
i = -1;
while (++i < 8)
{
if ((c >> i & 1) != 0)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
usleep(150);
}
}
int main(int argc, char **argv)
{
pid_t pid;
int i;
i = -1;
if (argc == 3)
{
pid = ft_atoi(argv[1]);
while (argv[2][++i])
send_bits(pid, argv[2][i]);
send_bits(pid, 0x00);
}
else
{
(void)argc;
write (1, "\e[5;91mWrong Format!!!\e[0m\n", 28);
write (1, "\e[4mPlease input pid and your message!\e[0m\n", 44);
exit(EXIT_FAILURE);
}
return (0);
}