commit b0ccba1b1bb6c0ab7932b0b2f405537e0862aefb Author: Kamil Bartczak Date: Sat Jan 12 22:50:44 2019 +0100 cw2zad3 diff --git a/cw2zad3/drugie/client b/cw2zad3/drugie/client new file mode 100755 index 0000000..ea7c70d Binary files /dev/null and b/cw2zad3/drugie/client differ diff --git a/cw2zad3/drugie/client.c b/cw2zad3/drugie/client.c new file mode 100644 index 0000000..a7e4ae9 --- /dev/null +++ b/cw2zad3/drugie/client.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFFER_SIZE 30000 +#define ATTEMPTS 100 + +char buf[BUFFER_SIZE]; + +/* +argv[1] - nazwa hosta +argv[2] - numer portu +*/ +int main(int argc, char **argv) +{ + struct sockaddr_in endpoint; + int sdsocket, addrlen, i, received; + struct hostent *he; + struct timeval time_b, time_e; + + if (argc<3) { + printf("podaj nazwe hosta i numer portu jako parametry\n"); + return 1; + } + + he = gethostbyname(argv[1]); + if (he == NULL) { + printf("Nieznany host: %s\n",argv[1]); + return 0; + } + + endpoint.sin_family = AF_INET; + endpoint.sin_port = htons(atoi(argv[2])); + endpoint.sin_addr = *(struct in_addr*) he->h_addr; + addrlen = sizeof(struct sockaddr_in); + + gettimeofday(&time_b, NULL); + for (i=0; i +#include +#include +#include +#include +#include +#include +#include +#include + +/* rozmiar bufora */ +#define BUFFER_SIZE 30000 + +/* liczba powtorzen */ +#define ATTEMPTS 100 + +char buf[BUFFER_SIZE]; + +/* +argv[1] - numer portu +*/ +int main(int argc, char **argv) +{ + struct sockaddr_in myaddr, endpoint; + int sdsocket, sdconnection, addrlen, received; + + if (argc < 2) { + printf("podaj numer portu jako parametr\n"); + return 1; + } + + sdsocket = socket(AF_INET, SOCK_DGRAM, 0); + addrlen = sizeof(struct sockaddr_in); + + myaddr.sin_family = AF_INET; + myaddr.sin_port = htons(atoi(argv[1])); + myaddr.sin_addr.s_addr = htonl(INADDR_ANY); + + if (bind(sdsocket,(struct sockaddr*) &myaddr,addrlen) < 0) { + printf("bind() nie powiodl sie\n"); + return 1; + } + + received = 0; + + while(1) { + /* odbior moze odbywac sie w mniejszych + segmentach */ + while (received < BUFFER_SIZE) + { + received += recvfrom(sdsocket, + buf+received, + BUFFER_SIZE-received, + 0, + (struct sockaddr*) &endpoint, + &addrlen); + } + + sendto(sdsocket, buf, BUFFER_SIZE, 0, (struct sockaddr*) &endpoint, addrlen); + } + + return 0; +} \ No newline at end of file diff --git a/cw2zad3/pierwsze/client b/cw2zad3/pierwsze/client new file mode 100755 index 0000000..4807a05 Binary files /dev/null and b/cw2zad3/pierwsze/client differ diff --git a/cw2zad3/pierwsze/client.c b/cw2zad3/pierwsze/client.c new file mode 100644 index 0000000..7d3a37f --- /dev/null +++ b/cw2zad3/pierwsze/client.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFFER_SIZE 30000 +#define ATTEMPTS 100 + +char buf[BUFFER_SIZE]; + +/* +argv[1] - nazwa hosta +argv[2] - numer portu +*/ +int main(int argc, char **argv) +{ + struct sockaddr_in endpoint; + int sdsocket, addrlen, i, received; + struct hostent *he; + struct timeval time_b, time_e; + + if (argc<3) { + printf("podaj nazwe hosta i numer portu jako parametry (provide hostname and port number in command line)\n"); + return 1; + } + + he = gethostbyname(argv[1]); + if (he == NULL) { + printf("Nieznany host (unknown kost): %s\n",argv[1]); + return 0; + } + + endpoint.sin_family = AF_INET; + endpoint.sin_port = htons(atoi(argv[2])); + endpoint.sin_addr = *(struct in_addr*) he->h_addr; + addrlen = sizeof(struct sockaddr_in); + + gettimeofday(&time_b, NULL); + for (i=0; i +#include +#include +#include +#include +#include +#include +#include +#include + +/* rozmiar bufora */ +#define BUFFER_SIZE 30000 + +/* liczba powtorzen */ +#define ATTEMPTS 100 + +char buf[BUFFER_SIZE]; + +/* +argv[1] - numer portu +*/ +int main(int argc, char **argv) +{ + struct sockaddr_in myaddr, endpoint; + int sdsocket, sdconnection, addrlen, received; + + if (argc < 2) { + printf("podaj numer portu jako parametr\n"); + return 1; + } + + sdsocket = socket(AF_INET, SOCK_STREAM, 0); + addrlen = sizeof(struct sockaddr_in); + + myaddr.sin_family = AF_INET; + myaddr.sin_port = htons(atoi(argv[1])); + myaddr.sin_addr.s_addr = htonl(INADDR_ANY); + + if (bind(sdsocket,(struct sockaddr*) &myaddr,addrlen) < 0) { + printf("bind() nie powiodl sie\n"); + return 1; + } + + if (listen(sdsocket, 10) < 0) { + printf("listen() nie powiodl sie\n"); + return 1; + } + + while ((sdconnection = + accept(sdsocket, + (struct sockaddr*) &endpoint, + &addrlen)) >= 0) + { + received = 0; + /* odbior moze odbywac sie w mniejszych + segmentach */ + while (received < BUFFER_SIZE) + { + received += recv(sdconnection, + buf+received, + BUFFER_SIZE-received, + 0); + } + send(sdconnection, buf, BUFFER_SIZE, 0); + close(sdconnection); + } + + close(sdsocket); + return 0; +} +