Adapted the apps to externalize the IP and mictcp port number as command line arguments
This commit is contained in:
parent
b6816aa736
commit
f9c78e2d36
3 changed files with 16 additions and 14 deletions
|
@ -4,15 +4,15 @@
|
|||
|
||||
#define MAX_SIZE 1000
|
||||
|
||||
int main()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int sockfd = 0;
|
||||
char chaine[MAX_SIZE];
|
||||
mic_tcp_sock_addr addr;
|
||||
addr.ip_addr.addr = "127.0.0.1";
|
||||
addr.ip_addr.addr_size = strlen("127.0.0.1") + 1;
|
||||
addr.port = 1234;
|
||||
addr.ip_addr.addr = argv[1];
|
||||
addr.ip_addr.addr_size = strlen(addr.ip_addr.addr) + 1;
|
||||
addr.port = atoi(argv[2]);
|
||||
|
||||
if ((sockfd = mic_tcp_socket(CLIENT)) == -1)
|
||||
{
|
||||
|
@ -38,6 +38,7 @@ int main()
|
|||
|
||||
printf("[TSOCK] Entrez vos message a envoyer, CTRL+D pour quitter\n");
|
||||
while(fgets(chaine, MAX_SIZE , stdin) != NULL) {
|
||||
chaine[strcspn(chaine, "\r\n")] = 0;
|
||||
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);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#define MAX_SIZE 1000
|
||||
|
||||
int main()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int sockfd;
|
||||
mic_tcp_sock_addr addr;
|
||||
|
@ -12,7 +12,7 @@ int main()
|
|||
|
||||
addr.ip_addr.addr = "127.0.0.1";
|
||||
addr.ip_addr.addr_size = strlen(addr.ip_addr.addr) + 1;
|
||||
addr.port = 1234;
|
||||
addr.port = atoi(argv[1]);
|
||||
|
||||
|
||||
if ((sockfd = mic_tcp_socket(SERVER)) == -1)
|
||||
|
@ -55,7 +55,7 @@ int main()
|
|||
printf("[TSOCK] Attente d'une donnee, appel de mic_recv ...\n");
|
||||
rcv_size = mic_tcp_recv(sockfd, chaine, MAX_SIZE);
|
||||
printf("[TSOCK] Reception d'un message de taille : %d\n", rcv_size);
|
||||
printf("[TSOCK] Message Recu : %s", chaine);
|
||||
printf("[TSOCK] Message Recu : %s\n", chaine);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
15
tsock_texte
15
tsock_texte
|
@ -2,39 +2,40 @@
|
|||
|
||||
puits=false
|
||||
sourc=false
|
||||
protocol="tcp"
|
||||
dest="127.0.0.1"
|
||||
|
||||
usage() { echo "Usage: $0 [-p|-s]" 1>&2; exit 1; }
|
||||
usage() { echo "Usage: $0 [-p|-s destination] port" 1>&2; exit 1; }
|
||||
|
||||
while getopts "pst:" o; do
|
||||
while getopts "ps:" o; do
|
||||
case "${o}" in
|
||||
p)
|
||||
puits=true
|
||||
;;
|
||||
s)
|
||||
sourc=true
|
||||
dest=${OPTARG}
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if ([ "$puits" = true ] && [ "$sourc" = true ]) || ([ "$puits" = false ] && [ "$sourc" = false ]) ; then
|
||||
if (([ "$sourc" = true ] && [ $# -ne 3 ]) || ([ "$puits" = true ] && [ $# -ne 2 ])) || (([ "$puits" = true ] && [ "$sourc" = true ]) || ([ "$puits" = false ] && [ "$sourc" = false ])) ; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
port=${@: -1}
|
||||
|
||||
if [ "$puits" = true ]; then
|
||||
cd build
|
||||
./server
|
||||
./server $port
|
||||
cd ..
|
||||
fi
|
||||
|
||||
if [ "$sourc" = true ]; then
|
||||
|
||||
cd build
|
||||
./client
|
||||
./client $dest $port
|
||||
cd ..
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in a new issue