Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi N - Z > Reti di calcolatori > [LAB] Programmazione di rete in C
Pages (2): « 1 [2]   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
GinoPilotino
.grande:maestro.

User info:
Registered: Dec 2002
Posts: 1403 (0.17 al dì)
Location: Segrate
Corso: TI.COM
Anno: Secondo
Time Online: 13 Days, 8:59:42 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

roberto a quando il codice funzionante tramite UDP?
o salvatore, illumina il mio cammino :D

24-01-2005 20:00
Click Here to See the Profile for GinoPilotino Click Here to See the Blog of GinoPilotino Click here to Send GinoPilotino a Private Message Find more posts by GinoPilotino Add GinoPilotino to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
futurbaggio
U Frikkettone

User info:
Registered: Feb 2003
Posts: 774 (0.09 al dì)
Location: Foggia
Corso: TIC
Anno: 1° Magistrale
Time Online: 13 Days, 16:44:00: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ecco i codici di una comunicazione UDP client-server in C.

Client.c

code:
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> main(){ int sd, rc, i; struct sockaddr_in clientAddress, serverAddress; struct hostent *hp; char buff_in[8000]; hp = gethostbyname("127.0.0.1"); serverAddress.sin_family = PF_INET; serverAddress.sin_addr.s_addr = ((struct in_addr*)(hp->h_addr))->s_addr; serverAddress.sin_port = htons(5001); sd = socket(AF_INET,SOCK_DGRAM,0); clientAddress.sin_family = PF_INET; clientAddress.sin_addr.s_addr = INADDR_ANY; clientAddress.sin_port = htons(0); rc = bind(sd, (struct sockaddr *) &clientAddress, sizeof(clientAddress)); printf("Messaggio da inviare al server UDP: "); scanf("%s", buff_in); rc = sendto(sd, buff_in, strlen(buff_in), 0, (struct sockaddr *)&serverAddress, sizeof(serverAddress)); close(sd); return EXIT_SUCCESS; }


Server.c
code:
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> main(){ int sd, rc, n, clientLength; struct sockaddr_in clientAddress, serverAddress; char buff_in[8000]; sd=socket(AF_INET, SOCK_DGRAM, 0); serverAddress.sin_family = PF_INET; serverAddress.sin_addr.s_addr = INADDR_ANY; serverAddress.sin_port = htons(5001); rc = bind (sd, (struct sockaddr *) &serverAddress,sizeof(serverAddress)); while(1) { clientLength = sizeof(clientAddress); n = recvfrom(sd, buff_in, sizeof(buff_in), 0, (struct sockaddr *) &clientAddress, &clientLength); printf("Ricevuto da %s:%d: %s \n",inet_ntoa(clientAddress.sin_addr.s_addr),ntohs(clientAddress.sin_port), buff_in); } return EXIT_SUCCESS; }


Roberto

__________________
E lo sceriffo americano non lo sa / ma quando parla ride tutta la città / vile fellone vieni a singolar tenzone / unza unza umpappà troppe truppe mariscià.
Non ci voleva l'eruzione della lava / e due piccioni si contendono la fava / sposa bagnata, bambina svergognata / la questione è delicata / come bolle la patata.
Basta! E' finita la festa
[L'ovile delle vanità, Folkabbestia]

25-01-2005 00:48
Click Here to See the Profile for futurbaggio Click Here to See the Blog of futurbaggio Click here to Send futurbaggio a Private Message Visit futurbaggio's homepage! Find more posts by futurbaggio Add futurbaggio to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 22:06.    Post New Thread    Post A Reply
Pages (2): « 1 [2]   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.076 seconds (57.68% PHP - 42.32% MySQL) con 24 query.