SRCDIR := src
-SOURCES := server.c \
+CLISOURCES := client.c \
-SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES))
+CLISOURCES := $(addprefix $(SRCDIR)/, $(CLISOURCES))
-OBJECTS := $(SOURCES:.c=.o)
+CLIOBJECTS := $(CLISOURCES:.c=.o)
-NAME := server
+SERVSOURCES := server.c \
+
+SERVSOURCES := $(addprefix $(SRCDIR)/, $(SERVSOURCES))
+
+SERVOBJECTS := $(SERVSOURCES:.c=.o)
+
+OBJECTS := $(SERVOBJECTS) $(CLIOBJECTS)
+
+NAME := server client
all : $(NAME)
debug : CFLAGS += -g
debug : $(NAME)
-$(NAME) : $(OBJECTS) Libft/libft.a
+server : $(SERVOBJECTS) Libft/libft.a
+ $(CC) $(CFLAGS) -o $@ $^
+
+client : $(CLIOBJECTS) Libft/libft.a
$(CC) $(CFLAGS) -o $@ $^
Libft/libft.a :
$(RM) $(OBJECTS)
$(foreach proj, $(SUBPROJECTS), $(MAKE) -C $(proj) clean)
-fclean : clean
+fclean :
+ $(RM) $(OBJECTS)
$(RM) $(NAME)
$(foreach proj, $(SUBPROJECTS), $(MAKE) -C $(proj) fclean)
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* client.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/01/20 17:15:06 by ljiriste #+# #+# */
+/* Updated: 2024/01/20 18:14:47 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+#include <limits.h>
+#include <signal.h>
+#include <unistd.h>
+
+void send(pid_t server_pid, const char *message)
+{
+ int char_bits_sent;
+ int char_ind;
+
+ char_bits_sent = 0;
+ char_ind = 0;
+ while (1)
+ {
+ if (message[char_ind] & 1 << char_bits_sent)
+ kill(server_pid, SIGUSR1);
+ else
+ kill(server_pid, SIGUSR2);
+ ++char_bits_sent;
+ if (char_bits_sent == CHAR_BIT && message[char_ind] == '\0')
+ break;
+ if (char_bits_sent == CHAR_BIT)
+ ++char_ind;
+ char_bits_sent %= CHAR_BIT;
+ usleep(1000);
+ }
+ return ;
+}
+
+int main(int argc, char **argv)
+{
+ pid_t server_pid;
+
+ if (argc != 3)
+ {
+ ft_printf("Invalid number of args. Th call should look like:\n"
+ "client SERVER_PID MESSAGE\n");
+ return (0);
+ }
+ server_pid = ft_atoi(argv[1]);
+ if (kill(server_pid, 0))
+ {
+ ft_printf("%i is not a valid PID.\n", server_pid);
+ return (0);
+ }
+ send(server_pid, argv[2]);
+ return (0);
+}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* main.c :+: :+: :+: */
+/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 15:12:04 by ljiriste #+# #+# */
-/* Updated: 2024/01/20 17:06:28 by ljiriste ### ########.fr */
+/* Updated: 2024/01/20 18:12:40 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
if (g_transfer.transfer_done)
{
ft_printf(g_transfer.string.vec);
+ ft_printf("\n");
ft_vec_forget_range(&g_transfer.string, g_transfer.string.size, 0);
g_transfer.transfer_done = 0;
}