[working] wysyla i odbiera dane

This commit is contained in:
2019-12-26 15:11:55 +01:00
parent fc65d4b146
commit dcfb945c0b
38 changed files with 442 additions and 18 deletions

View File

@@ -1,2 +1 @@
 server.cpp
Server.vcxproj -> C:\Users\bartool\MyData\MyCode\Cpp\VisualStudio_lap\LanChat\Debug\Server.exe
 Server.vcxproj -> C:\Users\bartool\MyData\MyCode\Cpp\VisualStudio_lap\LanChat\Debug\Server.exe

Binary file not shown.

Binary file not shown.

View File

@@ -1,6 +1,6 @@
//Server
#include <SocketLibrary/SocketLibrary.h>
#include <iostream>
using namespace SocketLibrary;
int main()
@@ -8,15 +8,41 @@ int main()
if (Network::Initialize() == true)
{
Log::Print("[SERVER] Winsok zostal zainicjolizowany. Mozemy dzialac.");
Socket socket;
if (socket.Create() == Result::Success)
Socket socketTCP(Protocol::TCP);
Socket socketUDP(Protocol::UDP);
if (socketTCP.Create() == Result::Success)
{
socketUDP.Create();
socketUDP.Bind(Endpoint("0.0.0.0", 54001));
Log::Print("[SERVER] Utworzylem gniazdo.");
socket.Close();
if (socketTCP.BindAndListen(Endpoint("127.0.0.1", 54000), 5) == Result::Success)
{
Log::Print("[SERVER] sukces");
Socket newConnection;
if (socketTCP.Accpet(newConnection) == Result::Success)
{
Log::Print("[SERVER] accept: sukces");
std::string buffer = "";
int size = 0;
while (true)
{
newConnection.ReciveAll(buffer, size);
std::cout << "[" << size << "] "<< buffer << std::endl;
buffer = "";
}
newConnection.Close();
}
else
{
Log::PrintError("[SERVER] accept: porazka", -1);
}
}
socketTCP.Close();
}
else
{
Log::PrintError("[SERVER] Nie udalo mi sie utworzyc gniazda.", -1);
Log::PrintError("[SERVER] porazka", -1);
}
}