diff --git a/SerwerC.c b/SerwerC.c new file mode 100644 index 0000000..bd754c3 --- /dev/null +++ b/SerwerC.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(void) +{ + + int Port; + char Buffor[1024]; + int gniazdo1, gniazdo2; + + struct sockaddr_in Serwer, Klient; + + socklen_t dl = sizeof(struct sockaddr_in); + + printf("Podaj port do nasłuchiwania:"); + scanf("%u", &Port); + gniazdo1 = socket(PF_INET, SOCK_STREAM, 0); + Serwer.sin_family = AF_INET; + Serwer.sin_port = htons(port); + Serwer.sin_addr.s_addr = INADDR_ANY; + + if (bind(gniazdo1, (struct sockaddr*) &Serwer, sizeof(Serwer < 0) + { + printf("Bind nie powiodl sie.\n"); + return 1; + + } + + if (listen(gniazdo1, 10) < 0) + { + printf("Listen nie powiodl sie.\n"); + return 1; + + } + + printf("Czekam na polaczenie ...\n"); + while ((gniazdo2 = accept(gniazdo1,(struct sockaddr*) &Klient, &dl)) > 0) + { + memset(bufor, 0, 1024); + recv(gniazdo2, bufor, 1024, 0); + printf("Wiadomosc od %s: %s\n",inet_ntoa(Klient.sin_addr),Buffor); + close(gniazdo2); + } + +close(gniazdo1); + return 0; +} + + +