diff --git a/Client/Debug/Client.log b/Client/Debug/Client.log index 4bcbbc6..a66f366 100644 --- a/Client/Debug/Client.log +++ b/Client/Debug/Client.log @@ -1 +1,2 @@ - Client.vcxproj -> C:\Users\bartool\MyData\MyCode\Cpp\VisualStudio_lap\LanChat\Debug\Client.exe + client.cpp + Client.vcxproj -> C:\Users\bartool\MyData\MyCode\Cpp\VisualStudio_lap\LanChat\Debug\Client.exe diff --git a/Client/Debug/Client.tlog/CL.read.1.tlog b/Client/Debug/Client.tlog/CL.read.1.tlog index 0908888..979b98e 100644 Binary files a/Client/Debug/Client.tlog/CL.read.1.tlog and b/Client/Debug/Client.tlog/CL.read.1.tlog differ diff --git a/Client/Debug/Client.tlog/link.read.1.tlog b/Client/Debug/Client.tlog/link.read.1.tlog index bdf266c..9e55b39 100644 Binary files a/Client/Debug/Client.tlog/link.read.1.tlog and b/Client/Debug/Client.tlog/link.read.1.tlog differ diff --git a/Client/Debug/Client.tlog/link.write.1.tlog b/Client/Debug/Client.tlog/link.write.1.tlog index 323d114..b49fa63 100644 Binary files a/Client/Debug/Client.tlog/link.write.1.tlog and b/Client/Debug/Client.tlog/link.write.1.tlog differ diff --git a/Client/Debug/vc142.idb b/Client/Debug/vc142.idb index 693ee12..e2b70ed 100644 Binary files a/Client/Debug/vc142.idb and b/Client/Debug/vc142.idb differ diff --git a/Client/Debug/vc142.pdb b/Client/Debug/vc142.pdb index 5effba5..3a544ab 100644 Binary files a/Client/Debug/vc142.pdb and b/Client/Debug/vc142.pdb differ diff --git a/Debug/Client.exe b/Debug/Client.exe index 7a584a2..d8de0c6 100644 Binary files a/Debug/Client.exe and b/Debug/Client.exe differ diff --git a/Debug/Client.ilk b/Debug/Client.ilk index 62ceda1..3195d27 100644 Binary files a/Debug/Client.ilk and b/Debug/Client.ilk differ diff --git a/Debug/Client.pdb b/Debug/Client.pdb index fb72a30..6ad9766 100644 Binary files a/Debug/Client.pdb and b/Debug/Client.pdb differ diff --git a/Debug/Server.exe b/Debug/Server.exe index eab83b9..9a20791 100644 Binary files a/Debug/Server.exe and b/Debug/Server.exe differ diff --git a/Debug/Server.ilk b/Debug/Server.ilk index d4a836f..276a71c 100644 Binary files a/Debug/Server.ilk and b/Debug/Server.ilk differ diff --git a/Debug/Server.pdb b/Debug/Server.pdb index 37922ea..0b9b346 100644 Binary files a/Debug/Server.pdb and b/Debug/Server.pdb differ diff --git a/Debug/SocketLibrary.lib b/Debug/SocketLibrary.lib index 7722257..c82d6ee 100644 Binary files a/Debug/SocketLibrary.lib and b/Debug/SocketLibrary.lib differ diff --git a/Debug/SocketLibrary.pdb b/Debug/SocketLibrary.pdb index 6cb42c2..ae0da1e 100644 Binary files a/Debug/SocketLibrary.pdb and b/Debug/SocketLibrary.pdb differ diff --git a/Server/Debug/Server.tlog/CL.read.1.tlog b/Server/Debug/Server.tlog/CL.read.1.tlog index 9b380da..4218e93 100644 Binary files a/Server/Debug/Server.tlog/CL.read.1.tlog and b/Server/Debug/Server.tlog/CL.read.1.tlog differ diff --git a/Server/Debug/Server.tlog/link.read.1.tlog b/Server/Debug/Server.tlog/link.read.1.tlog index b6e4b48..20f6377 100644 Binary files a/Server/Debug/Server.tlog/link.read.1.tlog and b/Server/Debug/Server.tlog/link.read.1.tlog differ diff --git a/Server/Debug/Server.tlog/link.write.1.tlog b/Server/Debug/Server.tlog/link.write.1.tlog index d91b346..da2e880 100644 Binary files a/Server/Debug/Server.tlog/link.write.1.tlog and b/Server/Debug/Server.tlog/link.write.1.tlog differ diff --git a/Server/Debug/vc142.idb b/Server/Debug/vc142.idb index 33d6396..b8a3bb1 100644 Binary files a/Server/Debug/vc142.idb and b/Server/Debug/vc142.idb differ diff --git a/Server/Debug/vc142.pdb b/Server/Debug/vc142.pdb index d2ef054..8ae89f3 100644 Binary files a/Server/Debug/vc142.pdb and b/Server/Debug/vc142.pdb differ diff --git a/Server/server.cpp b/Server/server.cpp index f09e4cb..2d86200 100644 --- a/Server/server.cpp +++ b/Server/server.cpp @@ -8,6 +8,16 @@ int main() if (Network::Initialize() == true) { Log::Print("[SERVER] Winsok zostal zainicjolizowany. Mozemy dzialac."); + Socket socket; + if (socket.Create() == Result::Success) + { + Log::Print("[SERVER] Utworzylem gniazdo."); + socket.Close(); + } + else + { + Log::PrintError("[SERVER] Nie udalo mi sie utworzyc gniazda.", -1); + } } diff --git a/SocketLibrary/Debug/SocketLibrary.idb b/SocketLibrary/Debug/SocketLibrary.idb index 74bd212..fa126dc 100644 Binary files a/SocketLibrary/Debug/SocketLibrary.idb and b/SocketLibrary/Debug/SocketLibrary.idb differ diff --git a/SocketLibrary/Debug/SocketLibrary.log b/SocketLibrary/Debug/SocketLibrary.log index ca229b0..f80f970 100644 --- a/SocketLibrary/Debug/SocketLibrary.log +++ b/SocketLibrary/Debug/SocketLibrary.log @@ -1,2 +1,2 @@ - Network.cpp + Socket.cpp SocketLibrary.vcxproj -> C:\Users\bartool\MyData\MyCode\Cpp\VisualStudio_lap\LanChat\Debug\SocketLibrary.lib diff --git a/SocketLibrary/Debug/SocketLibrary.pdb b/SocketLibrary/Debug/SocketLibrary.pdb index 6cb42c2..ae0da1e 100644 Binary files a/SocketLibrary/Debug/SocketLibrary.pdb and b/SocketLibrary/Debug/SocketLibrary.pdb differ diff --git a/SocketLibrary/Debug/SocketLibrary.tlog/CL.command.1.tlog b/SocketLibrary/Debug/SocketLibrary.tlog/CL.command.1.tlog index dd5358f..07d36d8 100644 Binary files a/SocketLibrary/Debug/SocketLibrary.tlog/CL.command.1.tlog and b/SocketLibrary/Debug/SocketLibrary.tlog/CL.command.1.tlog differ diff --git a/SocketLibrary/Debug/SocketLibrary.tlog/CL.read.1.tlog b/SocketLibrary/Debug/SocketLibrary.tlog/CL.read.1.tlog index 34177fb..f750538 100644 Binary files a/SocketLibrary/Debug/SocketLibrary.tlog/CL.read.1.tlog and b/SocketLibrary/Debug/SocketLibrary.tlog/CL.read.1.tlog differ diff --git a/SocketLibrary/Debug/SocketLibrary.tlog/CL.write.1.tlog b/SocketLibrary/Debug/SocketLibrary.tlog/CL.write.1.tlog index ab19db7..47be149 100644 Binary files a/SocketLibrary/Debug/SocketLibrary.tlog/CL.write.1.tlog and b/SocketLibrary/Debug/SocketLibrary.tlog/CL.write.1.tlog differ diff --git a/SocketLibrary/Debug/SocketLibrary.tlog/Lib-link.read.1.tlog b/SocketLibrary/Debug/SocketLibrary.tlog/Lib-link.read.1.tlog index 4a51eb5..609a4df 100644 Binary files a/SocketLibrary/Debug/SocketLibrary.tlog/Lib-link.read.1.tlog and b/SocketLibrary/Debug/SocketLibrary.tlog/Lib-link.read.1.tlog differ diff --git a/SocketLibrary/Debug/SocketLibrary.tlog/Lib-link.write.1.tlog b/SocketLibrary/Debug/SocketLibrary.tlog/Lib-link.write.1.tlog index b1b3eb6..08ae053 100644 Binary files a/SocketLibrary/Debug/SocketLibrary.tlog/Lib-link.write.1.tlog and b/SocketLibrary/Debug/SocketLibrary.tlog/Lib-link.write.1.tlog differ diff --git a/SocketLibrary/Debug/SocketLibrary.tlog/Lib.command.1.tlog b/SocketLibrary/Debug/SocketLibrary.tlog/Lib.command.1.tlog index e3ad30e..d4b8625 100644 Binary files a/SocketLibrary/Debug/SocketLibrary.tlog/Lib.command.1.tlog and b/SocketLibrary/Debug/SocketLibrary.tlog/Lib.command.1.tlog differ diff --git a/SocketLibrary/Log.cpp b/SocketLibrary/Log.cpp index a769493..aacd43e 100644 --- a/SocketLibrary/Log.cpp +++ b/SocketLibrary/Log.cpp @@ -1,12 +1,14 @@ #include #include "Log.h" +#include "Result.h" +#include "ipVersion.h" void SocketLibrary::Log::Print(std::string message) { - std::cout << message << std::endl; + std::cout << "[LOG] " << message << std::endl; } void SocketLibrary::Log::PrintError(std::string message, int error) { - std::cerr << "[Error Code: " << error << "] "<< message << std::endl; + std::cerr << "[ERROR] " << "[Error Code: " << error << "] "<< message << std::endl; } diff --git a/SocketLibrary/Result.h b/SocketLibrary/Result.h new file mode 100644 index 0000000..a389fea --- /dev/null +++ b/SocketLibrary/Result.h @@ -0,0 +1,10 @@ +#pragma once + +namespace SocketLibrary +{ + enum class Result + { + Success, + Fail + }; +} \ No newline at end of file diff --git a/SocketLibrary/Socket.cpp b/SocketLibrary/Socket.cpp new file mode 100644 index 0000000..9da6cef --- /dev/null +++ b/SocketLibrary/Socket.cpp @@ -0,0 +1,92 @@ +#include "Socket.h" +#include "Log.h" +#include + +namespace SocketLibrary +{ + Socket::Socket(IPVersion ipversion, SOCKET socket) + :_ipversion(ipversion),_socket(socket) + { + assert(_ipversion == IPVersion::IPv4); + + + } + + Result Socket::Create() + { + assert(_ipversion == IPVersion::IPv4); + + if (_socket != INVALID_SOCKET) + { + return Result::Fail; + } + + _socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (_socket == INVALID_SOCKET) + { + int error = WSAGetLastError(); + Log::PrintError("Nie udalo sie utworzyc gniazda", error); + return Result::Fail; + } + + Log::Print("Gniazdo zostalo utworzone."); + + if (SetSocketOption(SocketOption::TCP_NoDelay, TRUE) == Result::Success) + { + Log::Print("NoDelay zostalo wlaczone na gniezdzie."); + } + + return Result::Success; + } + + Result Socket::Close() + { + if (_socket == INVALID_SOCKET) + { + Log::PrintError("Niemozna zamknac nieistniejacego gniazda.", -1); + return Result::Fail; + } + + int result = closesocket(_socket); + if (result != 0) + { + int error = WSAGetLastError(); + Log::PrintError("Nie udalo sie zamknac gniazda.", error); + return Result::Fail; + } + + _socket = INVALID_SOCKET; + return Result::Success; + } + + SOCKET Socket::GetSocket() + { + return _socket; + } + + IPVersion Socket::GetIpVersion() + { + return _ipversion; + } + Result Socket::SetSocketOption(SocketOption option, BOOL value) + { + int result = 0; + switch (option) + { + case SocketOption::TCP_NoDelay: + result = setsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, (const char*)&value, sizeof(value)); + break; + default: + return Result::Fail; + } + + if (result != 0) + { + int error = WSAGetLastError(); + Log::PrintError("Nie mozna ustawic opcji dla gniazda.", error); + return Result::Fail; + } + + return Result::Success; + } +} \ No newline at end of file diff --git a/SocketLibrary/Socket.h b/SocketLibrary/Socket.h new file mode 100644 index 0000000..0cbacaa --- /dev/null +++ b/SocketLibrary/Socket.h @@ -0,0 +1,24 @@ +#pragma once +#include + +#include "ipVersion.h" +#include "Result.h" +#include "SocketOption.h" + +namespace SocketLibrary +{ + class Socket + { + public: + Socket(IPVersion ipversion = IPVersion::IPv4, SOCKET socket = INVALID_SOCKET); //(..., SocketHandle handle) + Result Create(); + Result Close(); + SOCKET GetSocket(); //SocketHandle GetHandle() + IPVersion GetIpVersion(); + private: + Result SetSocketOption(SocketOption option, BOOL value); + IPVersion _ipversion = IPVersion::IPv4; + SOCKET _socket = INVALID_SOCKET; + + }; +} \ No newline at end of file diff --git a/SocketLibrary/SocketLibrary.h b/SocketLibrary/SocketLibrary.h index 3ee2f67..6495508 100644 --- a/SocketLibrary/SocketLibrary.h +++ b/SocketLibrary/SocketLibrary.h @@ -1,3 +1,5 @@ #pragma once #include "Network.h" +#include "Socket.h" + #include "Log.h" \ No newline at end of file diff --git a/SocketLibrary/SocketLibrary.vcxproj b/SocketLibrary/SocketLibrary.vcxproj index 42d24af..d946323 100644 --- a/SocketLibrary/SocketLibrary.vcxproj +++ b/SocketLibrary/SocketLibrary.vcxproj @@ -142,13 +142,18 @@ + + + + + diff --git a/SocketLibrary/SocketLibrary.vcxproj.filters b/SocketLibrary/SocketLibrary.vcxproj.filters index 13fce30..899d66a 100644 --- a/SocketLibrary/SocketLibrary.vcxproj.filters +++ b/SocketLibrary/SocketLibrary.vcxproj.filters @@ -24,6 +24,18 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + @@ -32,5 +44,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/SocketLibrary/SocketOption.h b/SocketLibrary/SocketOption.h new file mode 100644 index 0000000..7e26577 --- /dev/null +++ b/SocketLibrary/SocketOption.h @@ -0,0 +1,9 @@ +#pragma once + +namespace SocketLibrary +{ + enum class SocketOption + { + TCP_NoDelay, + }; +} \ No newline at end of file diff --git a/SocketLibrary/ipVersion.h b/SocketLibrary/ipVersion.h new file mode 100644 index 0000000..9666153 --- /dev/null +++ b/SocketLibrary/ipVersion.h @@ -0,0 +1,12 @@ +#pragma once + +namespace SocketLibrary +{ + + enum class IPVersion + { + Unknown, + IPv4, + IPv6 + }; +} \ No newline at end of file