[Live-devel] Client IP address for RTSP streaming
Ross Finlayson
finlayson at live555.com
Wed Jun 21 07:52:12 PDT 2023
> On Jun 21, 2023, at 5:15 AM, Willdoner Christian via live-devel <live-devel at us.live555.com> wrote:
> Is it now possible to get the IP address from each client connected to the stream? If this is not easily done, the amount of connected clients would be sufficient.
> If doable, could you please share a code snippet?
The simplest way to do this is to define your own subclass of “RTSPServer”, and - in this subclass - redefine the virtual function “createNewClientConnection()” (which is called each time that a client connects to the server). E.g.
class myRTSPServer: public RTSPServer {
public:
static myRTSPServer* createNew(UsageEnvironment& env, Port ourPort = 554,
UserAuthenticationDatabase* authDatabase = NULL,
unsigned reclamationSeconds = 65) {
int ourSocketIPv4 = setUpOurSocket(env, ourPort, AF_INET);
int ourSocketIPv6 = setUpOurSocket(env, ourPort, AF_INET6);
if (ourSocketIPv4 < 0 && ourSocketIPv6 < 0) return NULL;
return new myRTSPServer(env, ourSocketIPv4, ourSocketIPv6, ourPort, authDatabase, reclamationTestSeconds);
}
private:
myRTSPServer(UsageEnvironment& env,
int ourSocketIPv4, int ourSocketIPv6, Port ourPort,
UserAuthenticationDatabase* authDatabase,
unsigned reclamationSeconds)
: RTSPServer(env, ourSocketIPv4, ourSocketIPv6, ourPort, authDatabase, reclamationTestSeconds) {}
myRTSPServer::~myRTSPServer() {}
virtual ClientConnection* createNewClientConnection(int clientSocket, struct sockaddr_storage const& clientAddr) {
// The client’s IP address is in “clientAddr”; do what you want with it here
// Then call the original function:
return RTSPServer::createNewClientConnection(clientSocket, clientAddr);
}
};
Then, in your application code call
myRTSPServer::createNew( … );
instead of
RTSPServer::createNew( … );
Ross Finlayson
Live Networks, Inc.
http://www.live555.com/
More information about the live-devel
mailing list