-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.c
79 lines (71 loc) · 1.76 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
70
71
72
73
74
75
76
77
78
79
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sahafid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/07 13:38:37 by sahafid #+# #+# */
/* Updated: 2022/02/07 13:38:40 by sahafid ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include "libft/libft.h"
#include "Printf/ft_printf.h"
#include <signal.h>
void bitshifting(int i, int fd)
{
int j;
j = 0;
while (j < 8)
{
if (i & (128 >> j))
kill(fd, SIGUSR1);
else
kill(fd, SIGUSR2);
usleep(600);
j++;
}
}
void send(int user)
{
if (user == SIGUSR1)
ft_printf("Message Sent\n");
}
void convertingascii(char *str, int fd)
{
int i;
i = 0;
while (str[i])
{
bitshifting(str[i], fd);
i++;
}
bitshifting('\0', fd);
}
int main(int argc, char *argv[])
{
struct sigaction sa;
int fd;
int i;
fd = 0;
i = 0;
sa.sa_handler = &send;
if (argc == 3)
{
while (argv[1][i])
{
if (ft_isalpha(argv[1][i]))
return (0);
i++;
}
fd = ft_atoi(argv[1]);
if (fd == -1 || fd == 0 || fd == 1)
return (0);
sigaction(SIGUSR1, &sa, NULL);
convertingascii(argv[2], fd);
}
return (0);
}