Serveur calculatrice

Serveur calculatrice

بواسطة - Mekki MEDKOUR
عدد الردود: 8

1•#include <sys/socket.j>

2 •#include <sys/types.j>

3•#include <net INET/in.h>

4•#include <stidlib.h>

5•#include <string.h>


6•int main (dar **argv int argc)

7• {

8•int nbr1 , nbr2,res, char op;

9• int==soket (AF_INET, SOCK_STRING, 1); 

10•Struct Sockaddr_In adrb, adra; 

11• adrb. sinfamily=af_inet; 

12•adrb. SinRorte=atoi(argv[1]); 

13•adrb.sinaddr.s_adr=inaddr_any; 

14•if(bind(s,&adrb, sizeof(adrb)>==1)

15•{

16•perror(bind) 

17•exit(-1); 

18•linten(s, 10); 

19•for( ) 

20• {

21•int L=sizeof (ADRa); 

22•int ss == accept (s,ADR,L); 

23•if (ss=0)

24• {

25•Perror (accept ); 

26•exit(0); 

27• } 

28• Recv (ss,&nbr1,sizeof (nbr1), 0); 

29• Recv (ss,&nbr2,sizeof (nbr2), 0); 

30• Recv (ss,&op,sizeof (op), 0);

31•if(op==+) res = nbr1+nb2;

32• else if(op==-) res = nbr1-nb2;

33•else if(op==*) res =nbr1*nb2;

34•else if(op==/) res = nbr1/nb2;

35•Send(ss,&res,sizeof(res),0); 

36.close(SS);

37.close(S); 

38.Return 0;

39.}

Remarque : 

يوجد أكثر من 20 خطأ ..ولمعرفة مستواك في هذا تمرين نعتبر كل خطا تستخرجه نقطة واحد من أصل 20 (note/20)

إجابة تكون عن طريق تحديد رقم سطر وتوضيح خطأ وممكن نفس سطر يحتوي علا عدة أخطاء أعزائي الطلبة 

ولكم خط 

وبالتوفيق للجميع

لمدة لا تتجاوز 3 أيام سأرسل لكم تصحيح هذا تمرين إن شاء الله 

وبارك الله فيكم جميعا 💙 ✨ 

رداً على Mekki MEDKOUR

Re: Serveur calculatrice

بواسطة - Nour Elhouda DJELLOULI
1•#include correction: #include 'sys/socket.h'

2 •#include correction: #include 'sys/types.h'
3•#include correction #include 'netint/in.h'
6•int main (dar **argv int argc ) correction int main(int argc,char**argv)
9• int==soket (AF_INET, SOCK_STRING, 1); corection 9• int s=soket (AF_INET, SOCK_STREM, 0);
11• adrb. sinfamily=af_inet; corection 11• adrb. sinfamily=AF_INET;
12•adrb. SinRorte=atoi(argv[1]); corection 12•adrb. Sinporte=atoi(argv[1]);
13•adrb.sinaddr.s_adr=inaddr_any; corection 13•adrb.sin_addr.s_adr=INADRR_ANY;
14•if(bind(s,&adrb, sizeof(adrb)>==1) CORECTION 14•if(bind(s,&adrb, sizeof(adrb)==-1)
15.perror("bind")
19•for( ) corection for( , ,)
21•int L=sizeof (ADRa) corection 21•int L=sizeof (adra);
22•int ss == accept (s,ADR,L); corection int ss == accept (s,&adra,&L);

23•if (ss=0) corection if (ss=-1)
25•Perror (accept ); corection Perror ("accept" );

26•exit(0) corection exit(-1)
31•if(op==+) res = nbr1+nb2; corection if(op='+') res = nbr1+nbr2;

32• else if(op==-) res = nbr1-nb2; corection if(op='-') res = nbr1+nbr2;

33•else if(op==*) res =nbr1*nb2; corection if(op='*') res = nbr1+nbr2;

34•else if(op==/) res = nbr1/nb2; corection if(op='/') res = nbr1+nbr2;
رداً على Nour Elhouda DJELLOULI

Re: Serveur calculatrice

بواسطة - Asmaa MOUSSAOUI
•#include correction: #include 'sys/socket.h'

2 •#include correction: #include 'sys/types.h'
3•#include correction #include 'netint/in.h'
6•int main (dar **argv int argc ) correction int main(int argc,char**argv)
9• int==soket (AF_INET, SOCK_STRING, 1); corection 9• int s=soket (AF_INET, SOCK_STREM, 0);
11• adrb. sinfamily=af_inet; corection 11• adrb. sinfamily=AF_INET;
12•adrb. SinRorte=atoi(argv[1]); corection 12•adrb. Sinporte=atoi(argv[1]);
13•adrb.sinaddr.s_adr=inaddr_any; corection 

رداً على Mekki MEDKOUR

Re: Serveur calculatrice

بواسطة - Mekki MEDKOUR
Solution juste :
1•#include 2 •#include 3•#include 4•#include 5•#include
6•int main (dar **argv int argc)
7• {
8•int nbr1 , nbr2,res, char op;
9• int==soket (AF_INET, SOCK_STRING, 0);
10•struct sockaddr_in adrb, adra;
11• adrb. sinfamily=AF_INET;
12•adrb. sinRorte=atoi(argv[1]);
13•adrb.sinaddr.s_adr=INADDR_ANY;
14•if(bind(s,&adrb, sizeof(adrb)>==-1)
15•{
16•perror("bind");
17•exit(-1);
18•linten(s, 10);
19•for( , ,)
20• {
21•int L=sizeof (adra);
22•int ss == accept (s,&adra,&L);
23•if (ss=-1)
24• {
25•perror ("accept ");
26•exit(-1);
27• }
28• recv (ss,&nbr1,sizeof (nbr1), 0);
29• recv (ss,&nbr2,sizeof (nbr2), 0);
30• recv (ss,&op,sizeof (op), 0);
31•if(op=='+') res = nbr1+nb2;
32• else if(op=='-') res = nbr1-nb2;
33•else if(op=='*') res =nbr1*nb2;
34•else if(op=='/') res = nbr1/nb2;
35•send(ss,&res,sizeof(res),0);
36.close(ss);
37.close(s);
38.return 0;
39.}
رداً على Mekki MEDKOUR

Re: Serveur calculatrice

بواسطة - Faten Hadil LABANI
1•#include'sys/socket.j' correction:'sys/socket.h'
2•#include'sys/types.j' correction: #include'sys/types.h'
3•#include 'net INET/in.h'correction: #include 'netint/in.h'
4•#include 'stidlib.h'correction: #include 'stdlib.h'
6•int main (dar **argv int argc ) correction: int main(int argc,char**argv)
9• int==soket (AF_INET, SOCK_STRING, 1); corection: int s=soket (AF_INET, SOCK_STREAM, 0);
11• adrb. sinfamily=af_inet; corection: adrb. sin_family=AF_INET;
12•adrb. SinRorte=atoi(argv[1]); corection: adrb. sin_porte=atoi(argv[1]);
13•adrb.sinaddr.s_adr=inaddr_any; corection: adrb.sin_addr.s_adr=INADRR_ANY;
14•if(bind(s,&adrb, sizeof(adrb)>==1) corection: if(bind(s,&adrb, sizeof(adrb)==-1)
16•perror(bind) corection: perror("bind");
•La fermuture de bind corection: }
19•for( ) corection: for( , ,)
21•int L=sizeof (ADRa) corection: int L=sizeof (adra);
22•int ss == accept (s,ADR,L); corection: int ss == accept (s,&adra,&L);
23•if (ss=0) corection: if (ss=-1)
25•Perror (accept ); corection: perror ("accept" );
26•exit(0) corection: exit(-1);
31•if(op==+) res = nbr1+nb2; corection: if(op='+') res = nbr1+nbr2;
32• else if(op==-) res = nbr1-nb2; corection: if(op='-') res = nbr1-nbr2;
33•else if(op==*) res =nbr1*nb2; corection: if(op='*') res = nbr1*nbr2;
34•else if(op==/) res = nbr1/nb2; corection: if(op='/') res = nbr1/nbr2;