Browse Source

vcc: write and receive

intirain 4 years ago
parent
commit
a8cf3de50d
3 changed files with 37 additions and 4 deletions
  1. 1 1
      Makefile
  2. 1 1
      include/vcc/version.h
  3. 35 2
      main.c

+ 1 - 1
Makefile

@@ -27,5 +27,5 @@ $(target) : 	$(objs) $(srcs)
 	@echo -e "CC\t\t\t$*.c"
 
 .PHONY clean : 
-	$(RM) $(objs)
+	$(RM) $(objs) $(target) -f  
 

+ 1 - 1
include/vcc/version.h

@@ -1 +1 @@
-#define VCCD_VERSION "vccd 0.1.0 Sat Feb 26 18:41:12 CST 2022 root"
+#define VCCD_VERSION "vccd 0.1.0 Fri Mar  4 22:03:55 CST 2022 root"

+ 35 - 2
main.c

@@ -89,17 +89,50 @@ static int init_socket(const char *server_addr) {
 }
 
 
+static int send_msg(const char *msg) {
+	char *buf;
+       
+	if (unlikely(!(buf = malloc(REQ_SIZE)))) {
+		fprintf(stderr, "*** malloc() failed\n");
+
+		exit(1);
+	}
+
+	strcpy(buf, msg);
+	write(fd, buf, REQ_SIZE);
+
+	free(buf);
+
+	return 0;
+}
+
+static int read_msg(char *buf) {
+	return read(fd, buf, REQ_SIZE);
+}
+
+
 int main(int argc, const char **argv) {
-	printf(VCCD_VERSION "\n");
+	char *buf;
 
 	if (unlikely(argc != 1 && argc != 2)) 
 		return usage();
 
+	printf(VCCD_VERSION "\n");
+
+	if (unlikely(!(buf = malloc(REQ_SIZE)))) {
+		fprintf(stderr, "*** malloc() failed\n");
+
+		return 1;
+	}
+
 	init_socket(argv[1] ? argv[1] : "124.223.105.230");
 
 	printf("Connected to server. \n");
 
-	for (;;);
+	send_msg("Hello, server! \n");
+	read_msg(buf);
+
+	printf(buf);
 
 	return 0;
 }