|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2123
|
Socket&C++
Dove trovo una libreria x il C++ che mi astragga un po i socket???
Non voglio librerie ultrafeaturate..........mi basta che faccia solo quello. Se poi e pure portabile è meglio. Tnk 1000000000
__________________
Gnu/Linux User ![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Spostato in programmazione...
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2123
|
up
__________________
Gnu/Linux User ![]() |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2123
|
della lib ACE che ne dite?
__________________
Gnu/Linux User ![]() |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Sinceramente, non sento il bisogno di particolari librerie per le letture da socket, in quanto le funzioni native POSIX di linux vanno bene e se vuoi sono utilizzabili anche su Win32 (la maggior parte).
Probabilmente alcuni toolkit (Qt, wxWidgets...) hanno anche un layer di astrazione socket, ma non vale la pena utilizzare quei "bisonti" se ti servono solo i socket. Le libACE non le ho mai utilizzate...
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Sicneramente i socket POSIX sono già molto portabili (anche su Windows cambia poco)... Usare una astrazione, per poi doverne usare un'altra (ad esempio na classe C++) diventa un po' pesante per una applicazione che magari necessita di prestazioni...
|
![]() |
![]() |
![]() |
#7 |
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2123
|
risolto:
Codice:
/** * A Sock Client Func */ #ifndef CLIENT_H #define CLIENT_H #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> /** Chiude */ void ChiudiSocket(int sock) { close (sock); return; } /** Crea */ int CreaSocket(char* Destinazione, int Porta) { struct sockaddr_in temp; struct hostent *h; int il_socket; int errore; temp.sin_family=AF_INET; temp.sin_port=htons(Porta); h=gethostbyname(Destinazione); if (h==0) { printf("Connessione IP alfanumerico... fallito!\n"); exit(1); } bcopy(h->h_addr,&temp.sin_addr,h->h_length); il_socket=socket(AF_INET,SOCK_STREAM,0); errore=connect(il_socket,(struct sockaddr*) &temp, sizeof(temp)); return il_socket; } /** Spedisce */ void SpedisciMessaggio (int sock, char* Messaggio) { prinft("%s\n", Messaggio); if (write(sock,Messaggio,strlen(Messaggio))<0) { prinft("Impossibile comunicare col server\n"); ChiudiSocket(sock); exit(1); } printf("Messaggio inviato!\n"); return; } #endif /** * A Sock Server Func */ #ifndef SERVER_H #define SERVER_H #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <fcntl.h> /** Crea */ int CreaServerSocket(int Porta) { int il_socket,errore; struct sockaddr_in temp; il_socket=socket(AF_INET,SOCK_STREAM,0); temp.sin_family=AF_INET; temp.sin_addr.s_addr=INADDR_ANY; temp.sin_port=htons(Porta); errore=fcntl(il_socket,F_SETFL,O_NONBLOCK); errore=bind(il_socket,(struct sockaddr*) &temp,sizeof(temp)); errore=listen(il_socket,7); return il_socket; } /** Chiude */ void ChiudiServerSocket(int sock) { close(sock); return; } #endif
__________________
Gnu/Linux User ![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 15:11.