dodaje wstępne pliki serweraC
This commit is contained in:
parent
848d990fcd
commit
7eb8452331
28
Makefile.win
Normal file
28
Makefile.win
Normal file
@ -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)
|
62
Server_C.dev
Normal file
62
Server_C.dev
Normal file
@ -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=
|
||||
|
8
Server_C.layout
Normal file
8
Server_C.layout
Normal file
@ -0,0 +1,8 @@
|
||||
[Editors]
|
||||
Order=0
|
||||
Focused=0
|
||||
[Editor_0]
|
||||
CursorCol=33
|
||||
CursorRow=34
|
||||
TopLine=1
|
||||
LeftChar=1
|
55
SerwerC.c
Normal file
55
SerwerC.c
Normal file
@ -0,0 +1,55 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdio.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user