implementato alcuni verifiche di errori. il file 11 e' incompleto e riguarda l'errore nel caso in cui un client legga da socket e il server e' terminato prematuramente
This commit is contained in:
BIN
10.client-server_recursive_kill_zombies_plus_err_accept/client
Executable file
BIN
10.client-server_recursive_kill_zombies_plus_err_accept/client
Executable file
Binary file not shown.
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
#include "../basic.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int sockfd;
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
|
||||||
|
if (argc != 3){
|
||||||
|
printf("usage: daytimecli <indirizzoIP> <porta> \n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){
|
||||||
|
printf("socket error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_port = htons(atoi(argv[2])); /* server port */
|
||||||
|
|
||||||
|
if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){
|
||||||
|
printf("inet_pton error for %s\n", argv[1]);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){
|
||||||
|
printf("connect error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/* Client che interroga un daytime server */
|
||||||
|
|
||||||
|
#include "../basic.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int sockfd, n;
|
||||||
|
char recvline[MAXLINE + 1];
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
|
||||||
|
if (argc != 3){
|
||||||
|
printf("usage: daytimecli <indirizzoIP> <porta> \n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){
|
||||||
|
printf("socket error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
bzero(&servaddr, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_port = htons(atoi(argv[2])); /* server port */
|
||||||
|
|
||||||
|
if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){
|
||||||
|
printf("inet_pton error for %s\n", argv[1]);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){
|
||||||
|
printf("connect error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,89 @@
|
|||||||
|
|
||||||
|
#include "../basic.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void sigchldaction (int signal){
|
||||||
|
|
||||||
|
int status, pid;
|
||||||
|
|
||||||
|
for (pid = waitpid(-1,&status,WNOHANG);pid > 0;pid = waitpid(-1,&status,WNOHANG)){
|
||||||
|
fprintf(stdout,"Server:Child %d terminated\n",pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
|
||||||
|
int listenfd, connfd, n;
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
char buff[INET_ADDRSTRLEN];
|
||||||
|
short port;
|
||||||
|
|
||||||
|
if (argc != 2 ){
|
||||||
|
printf("usage: daytimesrv <porta>\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
|
||||||
|
printf("socket error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_addr.s_addr = htonl(INADDR_ANY); /* wildcard address */
|
||||||
|
servaddr.sin_port = htons(atoi(argv[1])); /* server port */
|
||||||
|
|
||||||
|
if( (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr))) < 0){
|
||||||
|
printf("bind error\n"); exit(0);
|
||||||
|
}
|
||||||
|
if( listen(listenfd, 5) < 0 )
|
||||||
|
{ printf("listen error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in client_addr;
|
||||||
|
unsigned int client_addr_len = sizeof(client_addr);
|
||||||
|
|
||||||
|
struct sigaction sigchldstructure;
|
||||||
|
sigchldstructure.sa_handler = sigchldaction;
|
||||||
|
sigchldstructure.sa_flags = 0;
|
||||||
|
|
||||||
|
sigaction (SIGCHLD, &sigchldstructure, NULL);
|
||||||
|
|
||||||
|
for ( ; ; ) {
|
||||||
|
if( (connfd = accept(listenfd, (struct sockaddr *) &client_addr, &client_addr_len)) < 0)
|
||||||
|
{
|
||||||
|
if(errno == EINTR || errno==ECONNABORTED)
|
||||||
|
continue;
|
||||||
|
printf("accept error\n");
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int split = fork();
|
||||||
|
|
||||||
|
if ( split < 0) {
|
||||||
|
printf("fork for iterative server failed\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (split == 0){
|
||||||
|
close(listenfd);
|
||||||
|
|
||||||
|
inet_ntop(AF_INET, &(client_addr.sin_addr), buff, INET_ADDRSTRLEN); // get client address
|
||||||
|
port = ntohs(client_addr.sin_port);// get client port
|
||||||
|
fprintf (stdout,"%s%c%hu\n",buff,':',port);
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
printf("connection managed by a child process\n");
|
||||||
|
close(connfd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/* stampa l'ip del client */
|
||||||
|
|
||||||
|
#include "../basic.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int listenfd, connfd, n;
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
char buff[MAXLINE];
|
||||||
|
time_t ticks;
|
||||||
|
|
||||||
|
if (argc != 2 ){
|
||||||
|
printf("usage: daytimesrv <porta>\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
|
||||||
|
printf("socket error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
bzero(&servaddr, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_addr.s_addr = htonl(INADDR_ANY); /* wildcard address */
|
||||||
|
servaddr.sin_port = htons(atoi(argv[1])); /* server port */
|
||||||
|
|
||||||
|
if( (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr))) < 0){
|
||||||
|
printf("bind error\n"); exit(0);
|
||||||
|
}
|
||||||
|
if( listen(listenfd, 5) < 0 )
|
||||||
|
{ printf("listen error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
for ( ; ; ) {
|
||||||
|
if( (connfd = accept(listenfd, (struct sockaddr *) NULL, NULL)) < 0)
|
||||||
|
{ printf("accept error\n"); exit(0);} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
n=read(connfd, buff, MAXLINE);
|
||||||
|
fprintf (stdout,%s\n,buff);
|
||||||
|
close(connfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
all : server client
|
||||||
|
server : daytimesrv.o ../fun-corso-reti.o
|
||||||
|
gcc -o server daytimesrv.o ../fun-corso-reti.o
|
||||||
|
client : daytimecli.o ../fun-corso-reti.o
|
||||||
|
gcc -o client daytimecli.o ../fun-corso-reti.o
|
||||||
|
daytimesrv.o : daytimesrv.c ../basic.h
|
||||||
|
gcc -c -o daytimesrv.o daytimesrv.c
|
||||||
|
fun-corso-reti.o : ../fun-corso-reti.c ../basic.h
|
||||||
|
gcc -c -o ../fun-corso-reti.o ../fun-corso-reti.c
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
server : daytimesrv.o ../fun-corso-reti.o
|
||||||
|
gcc -o server daytimesrv.o ../fun-corso-reti.o
|
||||||
|
client : daytimecli.o ../fun-corso-reti.o
|
||||||
|
gcc -o client daytimecli.o ../fun-corso-reti.o
|
||||||
|
daytimesrv.o : daytimesrv.c ../basic.h
|
||||||
|
gcc -c -o daytimesrv.o daytimesrv.c
|
||||||
|
fun-corso-reti.o : ../fun-corso-reti.c ../basic.h
|
||||||
|
gcc -c -o ../fun-corso-reti.o ../fun-corso-reti.c
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
il server attende una connessione dal client
|
||||||
|
il server non blocca poiché e’ attivo in modo ricorsivo
|
||||||
|
il client si connette soltanto al server
|
||||||
|
il server rimuvoe i figli zombie mediante sigchld
|
||||||
BIN
10.client-server_recursive_kill_zombies_plus_err_accept/server
Executable file
BIN
10.client-server_recursive_kill_zombies_plus_err_accept/server
Executable file
Binary file not shown.
BIN
11.client-server-print-ip-port-bothv2/client
Executable file
BIN
11.client-server-print-ip-port-bothv2/client
Executable file
Binary file not shown.
76
11.client-server-print-ip-port-bothv2/daytimecli.c
Normal file
76
11.client-server-print-ip-port-bothv2/daytimecli.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "../basic.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int sockfd;
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
|
||||||
|
if (argc != 3){
|
||||||
|
printf("usage: daytimecli <indirizzoIP> <porta> \n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){
|
||||||
|
printf("socket error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
bzero(&servaddr, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_port = htons(atoi(argv[2])); /* server port */
|
||||||
|
|
||||||
|
if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){
|
||||||
|
printf("inet_pton error for %s\n", argv[1]);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){
|
||||||
|
printf("connect error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in r_server_local_addr;
|
||||||
|
unsigned int r_server_local_addr_len = sizeof(r_server_local_addr);
|
||||||
|
|
||||||
|
char * socket_buffer = (char *) malloc (r_server_local_addr_len) ;
|
||||||
|
int ridden;
|
||||||
|
ridden = read (sockfd, socket_buffer,r_server_local_addr_len );
|
||||||
|
fprintf(stdout,"Ho letto la prima volta %d bytes\n",ridden);
|
||||||
|
ridden = read (sockfd, socket_buffer,r_server_local_addr_len );
|
||||||
|
fprintf(stdout,"Ho letto la seconda volta %d bytes\n",ridden);
|
||||||
|
|
||||||
|
|
||||||
|
fprintf(stdout,"I'm sleeping for 20sec\n");
|
||||||
|
int left = sleep(20);
|
||||||
|
if (left == 0){
|
||||||
|
fprintf(stdout,"I'm here after 20 sec\n'");
|
||||||
|
}else{
|
||||||
|
fprintf(stdout,"Waked up before 20 sec\n'");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ridden = read (sockfd, socket_buffer,r_server_local_addr_len );
|
||||||
|
if (ridden < 0){
|
||||||
|
fprintf(stdout,"Errore durante la lettura\n");
|
||||||
|
exit(-1);
|
||||||
|
} else {
|
||||||
|
fprintf(stdout,"Ho letto la terza volta %d bytes\n",ridden);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
memcpy (&r_server_local_addr,socket_buffer, r_server_local_addr_len);
|
||||||
|
|
||||||
|
|
||||||
|
char buff[INET_ADDRSTRLEN];
|
||||||
|
short port;
|
||||||
|
|
||||||
|
inet_ntop(AF_INET, &(r_server_local_addr.sin_addr), buff, INET_ADDRSTRLEN);// get ip
|
||||||
|
port = ntohs(r_server_local_addr.sin_port);// get port
|
||||||
|
|
||||||
|
fprintf (stdout,"%s%c%hu\n",buff,':',port);
|
||||||
|
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
31
11.client-server-print-ip-port-bothv2/daytimecli.c~
Normal file
31
11.client-server-print-ip-port-bothv2/daytimecli.c~
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/* Client che interroga un daytime server */
|
||||||
|
|
||||||
|
#include "../basic.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int sockfd, n;
|
||||||
|
char recvline[MAXLINE + 1];
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
|
||||||
|
if (argc != 3){
|
||||||
|
printf("usage: daytimecli <indirizzoIP> <porta> \n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){
|
||||||
|
printf("socket error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
bzero(&servaddr, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_port = htons(atoi(argv[2])); /* server port */
|
||||||
|
|
||||||
|
if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){
|
||||||
|
printf("inet_pton error for %s\n", argv[1]);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){
|
||||||
|
printf("connect error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
BIN
11.client-server-print-ip-port-bothv2/daytimecli.o
Normal file
BIN
11.client-server-print-ip-port-bothv2/daytimecli.o
Normal file
Binary file not shown.
63
11.client-server-print-ip-port-bothv2/daytimesrv.c
Normal file
63
11.client-server-print-ip-port-bothv2/daytimesrv.c
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "../basic.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int listenfd, connfd, n;
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
char buff[INET_ADDRSTRLEN];
|
||||||
|
short port;
|
||||||
|
|
||||||
|
if (argc != 2 ){
|
||||||
|
printf("usage: daytimesrv <porta>\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
|
||||||
|
printf("socket error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
bzero(&servaddr, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_addr.s_addr = htonl(INADDR_ANY); /* wildcard address */
|
||||||
|
servaddr.sin_port = htons(atoi(argv[1])); /* server port */
|
||||||
|
|
||||||
|
if( (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr))) < 0){
|
||||||
|
printf("bind error\n"); exit(0);
|
||||||
|
}
|
||||||
|
if( listen(listenfd, 5) < 0 )
|
||||||
|
{ printf("listen error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in client_addr;
|
||||||
|
unsigned int client_addr_len = sizeof(client_addr);
|
||||||
|
|
||||||
|
struct sockaddr_in server_local_addr;
|
||||||
|
unsigned int server_local_addr_len = sizeof(server_local_addr);
|
||||||
|
|
||||||
|
char * socket_buffer = (char *) malloc (server_local_addr_len) ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for ( ; ; ) {
|
||||||
|
if( (connfd = accept(listenfd, (struct sockaddr *) &client_addr, &client_addr_len)) < 0)
|
||||||
|
{ printf("accept error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
inet_ntop(AF_INET, &(client_addr.sin_addr), buff, INET_ADDRSTRLEN);// get client ip
|
||||||
|
port = ntohs(client_addr.sin_port);// get client port
|
||||||
|
|
||||||
|
fprintf (stdout,"%s%c%hu\n",buff,':',port);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
getsockname (connfd, (struct sockaddr *) &server_local_addr, &server_local_addr_len);
|
||||||
|
memcpy (socket_buffer, &server_local_addr, server_local_addr_len);
|
||||||
|
write (connfd,socket_buffer, server_local_addr_len);
|
||||||
|
|
||||||
|
|
||||||
|
close(connfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
41
11.client-server-print-ip-port-bothv2/daytimesrv.c~
Normal file
41
11.client-server-print-ip-port-bothv2/daytimesrv.c~
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/* stampa l'ip del client */
|
||||||
|
|
||||||
|
#include "../basic.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int listenfd, connfd, n;
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
char buff[MAXLINE];
|
||||||
|
time_t ticks;
|
||||||
|
|
||||||
|
if (argc != 2 ){
|
||||||
|
printf("usage: daytimesrv <porta>\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
|
||||||
|
printf("socket error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
bzero(&servaddr, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_addr.s_addr = htonl(INADDR_ANY); /* wildcard address */
|
||||||
|
servaddr.sin_port = htons(atoi(argv[1])); /* server port */
|
||||||
|
|
||||||
|
if( (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr))) < 0){
|
||||||
|
printf("bind error\n"); exit(0);
|
||||||
|
}
|
||||||
|
if( listen(listenfd, 5) < 0 )
|
||||||
|
{ printf("listen error\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
for ( ; ; ) {
|
||||||
|
if( (connfd = accept(listenfd, (struct sockaddr *) NULL, NULL)) < 0)
|
||||||
|
{ printf("accept error\n"); exit(0);} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
n=read(connfd, buff, MAXLINE);
|
||||||
|
fprintf (stdout,%s\n,buff);
|
||||||
|
close(connfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
11.client-server-print-ip-port-bothv2/daytimesrv.o
Normal file
BIN
11.client-server-print-ip-port-bothv2/daytimesrv.o
Normal file
Binary file not shown.
9
11.client-server-print-ip-port-bothv2/makefile
Normal file
9
11.client-server-print-ip-port-bothv2/makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
all : server client
|
||||||
|
server : daytimesrv.o ../fun-corso-reti.o
|
||||||
|
gcc -o server daytimesrv.o ../fun-corso-reti.o
|
||||||
|
client : daytimecli.o ../fun-corso-reti.o
|
||||||
|
gcc -o client daytimecli.o ../fun-corso-reti.o
|
||||||
|
daytimesrv.o : daytimesrv.c ../basic.h
|
||||||
|
gcc -c -o daytimesrv.o daytimesrv.c
|
||||||
|
fun-corso-reti.o : ../fun-corso-reti.c ../basic.h
|
||||||
|
gcc -c -o ../fun-corso-reti.o ../fun-corso-reti.c
|
||||||
8
11.client-server-print-ip-port-bothv2/makefile~
Normal file
8
11.client-server-print-ip-port-bothv2/makefile~
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
server : daytimesrv.o ../fun-corso-reti.o
|
||||||
|
gcc -o server daytimesrv.o ../fun-corso-reti.o
|
||||||
|
client : daytimecli.o ../fun-corso-reti.o
|
||||||
|
gcc -o client daytimecli.o ../fun-corso-reti.o
|
||||||
|
daytimesrv.o : daytimesrv.c ../basic.h
|
||||||
|
gcc -c -o daytimesrv.o daytimesrv.c
|
||||||
|
fun-corso-reti.o : ../fun-corso-reti.c ../basic.h
|
||||||
|
gcc -c -o ../fun-corso-reti.o ../fun-corso-reti.c
|
||||||
5
11.client-server-print-ip-port-bothv2/readme
Normal file
5
11.client-server-print-ip-port-bothv2/readme
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
il server attende una connessione dal client e stampa ip e porta del client
|
||||||
|
il client si connette al server e stampa ip e porta del server
|
||||||
|
|
||||||
|
il client prova a leggere più volte, se non c’è niente da leggere le read dal socket restituisce 0.
|
||||||
|
L’idea è fare due letture. prima della seconda killare il server in modo da verificare l’errore ricevuto se il client prova a leggere. dopo la prima lettura c’è un wait
|
||||||
0
11.client-server-print-ip-port-bothv2/readme~
Normal file
0
11.client-server-print-ip-port-bothv2/readme~
Normal file
BIN
11.client-server-print-ip-port-bothv2/server
Executable file
BIN
11.client-server-print-ip-port-bothv2/server
Executable file
Binary file not shown.
Binary file not shown.
@@ -33,9 +33,7 @@ int main(int argc, char **argv) {
|
|||||||
char * socket_buffer = (char *) malloc (r_server_local_addr_len) ;
|
char * socket_buffer = (char *) malloc (r_server_local_addr_len) ;
|
||||||
int ridden;
|
int ridden;
|
||||||
ridden = read (sockfd, socket_buffer,r_server_local_addr_len );
|
ridden = read (sockfd, socket_buffer,r_server_local_addr_len );
|
||||||
fprintf(stdout,"Ho letto la prima volta %d\n bytes",ridden);
|
fprintf(stdout,"Ho letto %d\n bytes",ridden);
|
||||||
ridden = read (sockfd, socket_buffer,r_server_local_addr_len );
|
|
||||||
fprintf(stdout,"Ho letto la seconda volta %d\n bytes",ridden);
|
|
||||||
|
|
||||||
memcpy (&r_server_local_addr,socket_buffer, r_server_local_addr_len);
|
memcpy (&r_server_local_addr,socket_buffer, r_server_local_addr_len);
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -37,3 +37,8 @@ ntohs
|
|||||||
|
|
||||||
reti_readline
|
reti_readline
|
||||||
reti_writen
|
reti_writen
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
netstat -an -t | grep 9999
|
||||||
|
|||||||
Reference in New Issue
Block a user