added log.h and some update
This commit is contained in:
1 parent
8e54631e4b
commit
df50428f4c
4 files changed
+81
-32
No files matched your search
+14
-7
@@ -1,11 +1,12 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include "log.h"
|
||||
|
||||
#define PORT 5555
|
||||
#define PORT 7777
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
int main() {
|
||||
@@ -29,8 +30,8 @@ int main() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fork() == 0) {
|
||||
// Процесс чтения
|
||||
pid_t child_pid = fork();
|
||||
if (child_pid == 0) {
|
||||
while (1) {
|
||||
int valread = read(sock, buffer, BUFFER_SIZE);
|
||||
if (valread > 0) {
|
||||
@@ -40,13 +41,19 @@ int main() {
|
||||
}
|
||||
} else {
|
||||
char username[50];
|
||||
printf("Enter your username: ");
|
||||
fgets(username, 50, stdin);
|
||||
username[strlen(username)-1] = '\0';
|
||||
username[strlen(username) - 1] = '\0';
|
||||
send(sock, username, 50, 0);
|
||||
printf("username = %s\n", username);
|
||||
// Процесс отправки
|
||||
log_info("username = %s\n", username);
|
||||
while (1) {
|
||||
fgets(buffer, BUFFER_SIZE, stdin);
|
||||
if (strcmp(buffer, "/exit\n") == 0) {
|
||||
log_info("Client is exiting\n");
|
||||
kill(child_pid, SIGKILL);
|
||||
close(sock);
|
||||
break;
|
||||
}
|
||||
send(sock, buffer, strlen(buffer), 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user