From 7eb84523316563cd559c5b706384418be45ec0a6 Mon Sep 17 00:00:00 2001 From: Benny Date: Fri, 27 Dec 2019 22:35:17 +0100 Subject: [PATCH] =?UTF-8?q?dodaje=20wst=C4=99pne=20pliki=20serweraC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile.win | 28 ++++++++++++++++++++++ Server_C.dev | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ Server_C.layout | 8 +++++++ SerwerC.c | 55 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 Makefile.win create mode 100644 Server_C.dev create mode 100644 Server_C.layout create mode 100644 SerwerC.c diff --git a/Makefile.win b/Makefile.win new file mode 100644 index 0000000..4e8de3d --- /dev/null +++ b/Makefile.win @@ -0,0 +1,28 @@ +# Project: Server_C +# Makefile created by Dev-C++ 5.11 + +CPP = g++.exe +CC = gcc.exe +WINDRES = windres.exe +OBJ = SerwerC.o +LINKOBJ = SerwerC.o +LIBS = -L"D:/Dev-Cpp/MinGW64/lib" -L"D:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc +INCS = -I"D:/Dev-Cpp/MinGW64/include" -I"D:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" +CXXINCS = -I"D:/Dev-Cpp/MinGW64/include" -I"D:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" +BIN = Server_C.exe +CXXFLAGS = $(CXXINCS) +CFLAGS = $(INCS) +RM = rm.exe -f + +.PHONY: all all-before all-after clean clean-custom + +all: all-before $(BIN) all-after + +clean: clean-custom + ${RM} $(OBJ) $(BIN) + +$(BIN): $(OBJ) + $(CC) $(LINKOBJ) -o $(BIN) $(LIBS) + +SerwerC.o: SerwerC.c + $(CC) -c SerwerC.c -o SerwerC.o $(CFLAGS) diff --git a/Server_C.dev b/Server_C.dev new file mode 100644 index 0000000..fe21214 --- /dev/null +++ b/Server_C.dev @@ -0,0 +1,62 @@ +[Project] +FileName=Server_C.dev +Name=Server_C +Type=1 +Ver=2 +ObjFiles= +Includes= +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=0 +Icon= +ExeOutput= +ObjectOutput= +LogOutput= +LogOutputEnabled=0 +OverrideOutput=0 +OverrideOutputName= +HostApplication= +UseCustomMakefile=0 +CustomMakefile= +CommandLine= +Folders= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000000 +UnitCount=1 + +[VersionInfo] +Major=1 +Minor=0 +Release=0 +Build=0 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 +SyncProduct=1 + +[Unit1] +FileName=SerwerC.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/Server_C.layout b/Server_C.layout new file mode 100644 index 0000000..2bc41dd --- /dev/null +++ b/Server_C.layout @@ -0,0 +1,8 @@ +[Editors] +Order=0 +Focused=0 +[Editor_0] +CursorCol=33 +CursorRow=34 +TopLine=1 +LeftChar=1 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; +} + + +