"depot M311"
This commit is contained in:
62
S3T_TP_08_TCP-IP/DEMOS/client_tcp.c
Normal file
62
S3T_TP_08_TCP-IP/DEMOS/client_tcp.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/******************************************************/
|
||||
/* S3T - M311 - CHIGNOLI */
|
||||
/* Client IPC/BERKELEY -- DOMAINE INET -- MODE TCP */
|
||||
/* A FINIR - A FINIR -A FINIR - A FINIR - A FINIR */
|
||||
/******************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define BUFSIZE 80
|
||||
int sd;
|
||||
|
||||
int main (int argc, char* argv [])
|
||||
{
|
||||
char buffer [BUFSIZE];
|
||||
struct hostent *host_name;
|
||||
struct sockaddr_in socket_name;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
printf ("\nSYNTAXE : %s <machine>\n\n", argv[0]); exit (1);
|
||||
}
|
||||
|
||||
/* Obtention d'un descripteur de "socket" */
|
||||
if ((sd = socket (PF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
{ perror ("*** Echec socket ***"); exit (2); }
|
||||
|
||||
/* Recherche de l'adresse INTERNET de la machine du serveur */
|
||||
host_name = gethostbyname (argv[1]);
|
||||
if (host_name == 0)
|
||||
{ fprintf (stderr, "\n*** Echec gethostbyname ***\n\n"); exit(1); }
|
||||
|
||||
/* Paramétrage de la "socket" */
|
||||
bzero ( (char *) &socket_name, sizeof (socket_name) ); // mise à zero
|
||||
socket_name.sin_family = AF_INET;
|
||||
socket_name.sin_port = 6200;
|
||||
bcopy (host_name -> h_addr, &socket_name.sin_addr, host_name -> h_length);
|
||||
|
||||
/* Affichage infos socket */
|
||||
printf ("CLIENT sur machine %s (%u) - port %d\n",
|
||||
inet_ntoa (socket_name.sin_addr),
|
||||
socket_name.sin_addr, socket_name.sin_port);
|
||||
|
||||
/**************************************************/
|
||||
/* A FAIRE : */
|
||||
/* - demande de connexion */
|
||||
/* - envoi de 80 caracteres au serveur */
|
||||
/* - recuperation de 80 caracteres du serveur */
|
||||
/* - affichage des 80 caractères retournés */
|
||||
/**************************************************/
|
||||
}
|
||||
}
|
||||
|
||||
|
13
S3T_TP_08_TCP-IP/DEMOS/demo_dialogue.c
Normal file
13
S3T_TP_08_TCP-IP/DEMOS/demo_dialogue.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
char buffer [80];
|
||||
if (argc != 2) fprintf (stderr, "\nERREUR ... Syntaxe : %s nom_login\n\n", argv[0]), exit(1);
|
||||
|
||||
bzero (buffer, 80); // les '\0' sur 80 caracteres !!
|
||||
sprintf (buffer, "%s OUI",argv[1]);
|
||||
printf ("*%s*\n", buffer);
|
||||
}
|
13
S3T_TP_08_TCP-IP/DEMOS/demo_echange.c
Normal file
13
S3T_TP_08_TCP-IP/DEMOS/demo_echange.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
char buffer [80];
|
||||
if (argc != 2) fprintf (stderr, "\nERREUR ... Syntaxe : %s chaine\n\n", argv[0]), exit(1);
|
||||
bzero (buffer, 80);
|
||||
strcpy (buffer, argv[1]);
|
||||
printf ("\nBuffer a envoyer ou a recevoir : %s\n\n", buffer);
|
||||
}
|
75
S3T_TP_08_TCP-IP/DEMOS/demo_serveur_tcp.c
Normal file
75
S3T_TP_08_TCP-IP/DEMOS/demo_serveur_tcp.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/******************************************************/
|
||||
/* S3T - M311 - CHIGNOLI */
|
||||
/* Serveur IPC/BERKELEY -- DOMAINE INET -- MODE TCP */
|
||||
/* A FINIR - A FINIR -A FINIR - A FINIR - A FINIR */
|
||||
/******************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define BUFSIZE 80
|
||||
int sd;
|
||||
|
||||
void arret_service()
|
||||
{
|
||||
printf("\n SERVEUR : SIGINT recu => Arret du SERVICE\n\n");
|
||||
close(sd);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
int main (int argc, char* argv [])
|
||||
{
|
||||
char buffer [BUFSIZE];
|
||||
struct hostent *host_name;
|
||||
struct sockaddr_in socket_name;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
printf ("\nSYNTAXE : %s <machine>\n\n", argv[0]); exit (1);
|
||||
}
|
||||
/* Armement du signal SIGINT pour arret "propre" du serveur */
|
||||
signal(SIGINT,arret_service);
|
||||
|
||||
/* Obtention d'un descripteur de "socket" */
|
||||
if ((sd = socket (PF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
{ perror ("*** Echec socket ***"); exit (2); }
|
||||
|
||||
/* Recherche de l'adresse INTERNET de la machine du serveur */
|
||||
host_name = gethostbyname (argv[1]);
|
||||
if (host_name == 0)
|
||||
{ fprintf (stderr, "\n*** Echec gethostbyname ***\n\n"); exit(1); }
|
||||
|
||||
/* Paramétrage de la "socket" */
|
||||
bzero ( (char *) &socket_name, sizeof (socket_name) ); // mise à zero
|
||||
socket_name.sin_family = AF_INET;
|
||||
socket_name.sin_port = 6200;
|
||||
bcopy (host_name -> h_addr, &socket_name.sin_addr, host_name -> h_length);
|
||||
|
||||
/* Affichage infos socket */
|
||||
printf ("SERVEUR sur machine %s (%u) - port %d\n",
|
||||
inet_ntoa (socket_name.sin_addr),
|
||||
socket_name.sin_addr, socket_name.sin_port);
|
||||
|
||||
/**************************************************/
|
||||
/* A FAIRE : Suite du parametrage du "serveur" */
|
||||
/**************************************************/
|
||||
|
||||
/* Boucle de traitement des demandes de connexion */
|
||||
while (1)
|
||||
{
|
||||
/**************************************************/
|
||||
/* A FAIRE : Attente des demandes de connexion */
|
||||
/* d'un client et traitement. */
|
||||
/**************************************************/
|
||||
}
|
||||
}
|
||||
|
||||
|
13
S3T_TP_08_TCP-IP/DEMOS/demo_wait3.c
Normal file
13
S3T_TP_08_TCP-IP/DEMOS/demo_wait3.c
Normal file
@@ -0,0 +1,13 @@
|
||||
:*******************************/
|
||||
/* handler de signaux SIGCHILD */
|
||||
/* Comptage de fin de fils */
|
||||
/*******************************/
|
||||
|
||||
void handler_SIGCHLD()
|
||||
/* Pour eliminer les zombies */
|
||||
{
|
||||
while (wait3 (NULL, WNOHANG, NULL) > 0)
|
||||
{
|
||||
nb_fils--;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user