-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
64 lines (60 loc) · 1.65 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lvincent <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 10:38:11 by lvincent #+# #+# */
/* Updated: 2023/04/18 18:51:38 by lvincent ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
static void ft_send_msg(int pid, char *msg)
{
int i;
int shift;
i = 32;
while (i--)
{
if ((ft_strlen(msg) >> i) & 1)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
usleep(100);
}
i = -1;
while (msg[++i])
{
shift = 8;
while (shift--)
{
if ((msg[i] >> shift) & 1)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
usleep(100);
}
}
}
int main(int argc, char **argv)
{
if (argc != 3)
{
ft_printf("Invalid use of the command\n");
ft_printf("format : ./client <server pid> \"Your message\"\n");
return (0);
}
if (!ft_strlen(argv[2]))
{
ft_printf("The message string must mot be empty\n");
return (0);
}
if (argv[2] < 0)
{
ft_printf("Invalid PID");
return (0);
}
ft_send_msg(ft_atoi(argv[1]), argv[2]);
return (0);
}