Skip to content

Commit 5d34b43

Browse files
author
Alexandre jublot
committed
feat: added getRunningPort method on UDP and TCP servers
1 parent a44f194 commit 5d34b43

4 files changed

Lines changed: 22 additions & 0 deletions

File tree

include/Polymorph/Network/tcp/Server.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ namespace polymorph::network::tcp
5454
public:
5555
void start();
5656

57+
/**
58+
* @brief get the port used by the server
59+
* @return The port number
60+
*/
61+
std::uint16_t getRunningPort() const;
62+
5763
template<typename T>
5864
void sendTo(OpId opId, T &data, SessionId sessionId, std::function<void(const PacketHeader &, const T &)> callback = nullptr)
5965
{

include/Polymorph/Network/udp/Server.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ namespace polymorph::network::udp
5959

6060
/////////////////////////////// METHODS /////////////////////////////////
6161
public:
62+
/**
63+
* @brief get the port used by the server
64+
* @return The port number
65+
*/
66+
std::uint16_t getRunningPort() const;
67+
6268
/**
6369
* @brief Method called when an ack packet is received, it confirm the reception and discard the auto re-send feature for the packet
6470
* @param from The recipient of the initial packet

src/src/tcp/Server.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ polymorph::network::tcp::Server::~Server()
3838
if (!_context.stopped())
3939
_context.stop();
4040
}
41+
42+
std::uint16_t polymorph::network::tcp::Server::getRunningPort() const
43+
{
44+
return _acceptor.local_endpoint().port();
45+
}

src/src/udp/Server.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,8 @@ void polymorph::network::udp::Server::_handleSessionTransfer(const asio::ip::udp
122122

123123
sendTo<SessionTransferResponseDto>(SessionTransferResponseDto::opId, response, packet.header.sId);
124124
}
125+
126+
std::uint16_t polymorph::network::udp::Server::getRunningPort() const
127+
{
128+
return _socket.local_endpoint().port();
129+
}

0 commit comments

Comments
 (0)