46 wiersze
1,3 KiB
C
46 wiersze
1,3 KiB
C
#include <mictcp.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define MAX_SIZE 1000
|
|
|
|
#define COLOR_RED "\x1b[31m"
|
|
#define COLOR_GREEN "\x1b[32m"
|
|
#define COLOR_BOLD "\x1b[1m"
|
|
#define COLOR_RESET "\x1b[0m"
|
|
|
|
int main() {
|
|
|
|
int sockfd = 0;
|
|
char chaine[MAX_SIZE];
|
|
mic_tcp_sock_addr addr;
|
|
addr.ip_addr = "127.0.0.1";
|
|
addr.port = 1234;
|
|
|
|
if ((sockfd = mic_tcp_socket(CLIENT)) == -1) {
|
|
printf("[TSOCK] Creation du socket MICTCP: "COLOR_RED"ERREUR"COLOR_RESET"\n");
|
|
return 1;
|
|
} else {
|
|
printf("[TSOCK] Creation du socket MICTCP: "COLOR_GREEN"OK"COLOR_RESET"\n");
|
|
}
|
|
|
|
if (mic_tcp_connect(sockfd, addr) == -1) {
|
|
printf("[TSOCK] Connexion du socket MICTCP: "COLOR_RED"ERREUR"COLOR_RESET"\n");
|
|
return 1;
|
|
} else {
|
|
printf("[TSOCK] Connexion du socket MICTCP: "COLOR_GREEN"OK"COLOR_RESET"\n");
|
|
}
|
|
|
|
memset(chaine, 0, MAX_SIZE);
|
|
|
|
printf(COLOR_BOLD"[TSOCK] Entrez vos message a envoyer, CTRL+D pour quitter"COLOR_RESET"\n");
|
|
while (fgets(chaine, MAX_SIZE, stdin) != NULL) {
|
|
int sent_size = mic_tcp_send(sockfd, chaine, strlen(chaine) + 1);
|
|
printf("[TSOCK] Appel de mic_send avec un message de taille : %lu\n", strlen(chaine) + 1);
|
|
printf("[TSOCK] Appel de mic_send valeur de retour : %d\n", sent_size);
|
|
}
|
|
|
|
mic_tcp_close(sockfd);
|
|
|
|
return 0;
|
|
}
|