Skip to content

Commit

Permalink
ClientSideNetUdp: add sendTo() method, set setIpv6Only(false) in star…
Browse files Browse the repository at this point in the history
…t() method
  • Loading branch information
JonathSpirit committed Jan 4, 2025
1 parent 08b06d6 commit 1b7d45f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
3 changes: 3 additions & 0 deletions includes/FastEngine/network/C_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ class FGE_API ClientSideNetUdp : public NetFluxUdp

[[nodiscard]] Identity const& getClientIdentity() const;

template<class TPacket = Packet>
void sendTo(TransmissionPacketPtr& pck, Identity const& id);

[[nodiscard]] FluxProcessResults process(FluxPacketPtr& refFluxPacket);

Client _client; //But it is the server :O
Expand Down
41 changes: 32 additions & 9 deletions includes/FastEngine/network/C_server.inl
Original file line number Diff line number Diff line change
Expand Up @@ -233,26 +233,49 @@ bool ClientSideNetUdp::start(Port bindPort,
return false;
}
this->g_socket.setAddressType(addressType);
if (addressType == IpAddress::Types::Ipv6)
{
this->g_socket.setIpv6Only(false);
}

if (this->g_socket.bind(bindPort, bindIp) == Socket::Errors::ERR_NOERROR)
{
if (this->g_socket.connect(connectRemoteAddress, connectRemotePort) == Socket::Errors::ERR_NOERROR)
if (this->g_socket.connect(connectRemoteAddress, connectRemotePort) != Socket::Errors::ERR_NOERROR)
{
this->g_clientIdentity._ip = connectRemoteAddress;
this->g_clientIdentity._port = connectRemotePort;
this->g_socket.close();
return false;
}

this->g_running = true;
this->g_clientIdentity._ip = connectRemoteAddress;
this->g_clientIdentity._port = connectRemotePort;

this->g_threadReception = std::make_unique<std::thread>(&ClientSideNetUdp::threadReception<TPacket>, this);
this->g_threadTransmission =
std::make_unique<std::thread>(&ClientSideNetUdp::threadTransmission<TPacket>, this);
this->g_running = true;

return true;
}
this->g_threadReception = std::make_unique<std::thread>(&ClientSideNetUdp::threadReception<TPacket>, this);
this->g_threadTransmission =
std::make_unique<std::thread>(&ClientSideNetUdp::threadTransmission<TPacket>, this);

return true;
}
this->g_socket.close();
return false;
}

template<class TPacket>
void ClientSideNetUdp::sendTo(TransmissionPacketPtr& pck, Identity const& id)
{ ///TODO: have a transmission queue ?
if (!pck->packet() || !pck->packet().haveCorrectHeaderSize())
{ //Last verification of the packet
return;
}

pck->doNotReorder();

std::scoped_lock const lock(this->_g_mutexFlux);
TPacket packet = pck->packet();
this->g_socket.send(pck->packet());
}

template<class TPacket>
void ClientSideNetUdp::threadReception()
{
Expand Down

0 comments on commit 1b7d45f

Please sign in to comment.