summaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'client.c')
-rw-r--r--client.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/client.c b/client.c
new file mode 100644
index 0000000..843bf52
--- /dev/null
+++ b/client.c
@@ -0,0 +1,52 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* client.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: kdx <kdx @student.42angouleme.fr +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2022/10/09 03:36:54 by kdx #+# #+# */
+/* Updated: 2022/10/12 05:38:29 by kdx ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft/libft.h"
+#include <sys/types.h>
+#include <signal.h>
+#include <unistd.h>
+
+static void send(const unsigned char *s, pid_t pid)
+{
+ size_t bit;
+ int sig;
+ size_t i;
+
+ i = 0;
+ while (1)
+ {
+ bit = 0;
+ while (bit < 8)
+ {
+ sig = SIGUSR1;
+ if (s[i] & (1 << bit))
+ sig = SIGUSR2;
+ kill(pid, sig);
+ usleep(50 + i / 100);
+ bit++;
+ }
+ if (s[i] == '\0')
+ break ;
+ i++;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ pid_t server_pid;
+
+ if (argc != 3)
+ return (1 | ft_dprintf(2, "usage: client <server PID> <string>\n"));
+ server_pid = ft_atoi(argv[1]);
+ send((const unsigned char *)argv[2], server_pid);
+ return (0);
+}