client's ip address

Hi All,

I would like to retrieve the IP addresses from all connected client. I used:

IApplicationInstance applicationInstance = client.getAppInstance();

MediaStreamMap msm = (MediaStreamMap) applicationInstance.getStreams();

String ip = (String) msm.getStream(streams.get(index)).getHTTPStreamerSession().getIpAddress();

but it threw a NullPointerException.

Can someone give me some advises?

Try it like this:

public void getClientIps(IClient client, RequestFunction function,
			AMFDataList params) {
		List<IClient> clients = client.getAppInstance().getClients();
		Iterator<IClient> iter = clients.iterator();
		while(iter.hasNext())
		{
			IClient aclient = iter.next();
			if (!aclient.isConnected())
				continue;
			getLogger().info("Client IP" + aclient.getIp());
			
		}
}

Richard

Show the code you are using to count the number of streams.

Charlie

Actually I think you want more that that, you also want the IP of all the HTTPStreamerSessions. I dont have the concise example right this minute, but take a look at this post and see if you can suss it out:

http://community.wowza.com/t/-/84

Richard

Actually, Wowza doesn’t do any encoding, transcoding or compression.

Richard

There are a lot of options in the Live Encoder section:

http://community.wowza.com/c/-/8

Richard

This covers cupertino, smooth and sanjose:

https://www.wowza.com/docs/how-to-control-access-to-http-streams-cupertinostreaming-sanjosestreaming-smoothstreaming-mpegdashstreaming

And this for RTSP:

https://www.wowza.com/docs/how-to-control-access-to-rtsp-rtp-streams

Richard

onHTTPSessionCreate/Destroy is what you have to work with, they are methods of IHTTPStreamerSessionNotify. I would get statistics from the log files.

Richard

Thank you Richard,

client.getIp() does well,

but I am just curious about my code. did anything go wrong. Since I would like to retrieve the ip address corresponding to each stream.

Thank you Richard, you always been really helpful!!!

Hi Richard,

I found a funny thing while I tried to get the MediaStreamMap.

IApplicationInstance applicationInstance = client.getAppInstance();

MediaStreamMap msm = (MediaStreamMap) applicationInstance.getStreams();

msm contained all the connected streams, the funny thing is if only one stream in msm, it would just have one stream in the map. if there are two or more streams, each stream would have one duplicated stream. So say if there are 3 stream connected, there would have 6 streams in the msm. I wonder if you notice this?

Here is my code:

public void getConnectedClientInfo(IClient client, RequestFunction function, AMFDataList params)

{

getLogger().info(“getConnectedClinetInfo retrieving info…”);

AMFDataArray retArray = new AMFDataArray();

AMFDataObj retObj = null;

IApplicationInstance applicationInstance = client.getAppInstance();

List streams = applicationInstance.getStreams().getPublishStreamNames();

MediaStreamMap msm = (MediaStreamMap) applicationInstance.getStreams();

List streamList = new ArrayList();

streamList = msm.getStreams();

if(streamList.size()>0) {

for(int i=0;i<streamList.size();i++)

getLogger().info(streamList.size()+ “…”+streamList.get(i).getClientId());

}

getLogger().info(“MSM COUNTER”+msm.getCount());

for(int i=0;i<streams.size();i++){

getLogger().info(streams.get(i)+" Streams size: "+streams.size());

retObj = new AMFDataObj();

if(streams.get(i)!=null) {

String str = new String(streams.get(i));

retObj.put(“room”, new AMFDataItem(str.substring(0,5)));

getLogger().info("Room number: "+str.substring(0,5));

String id = str.substring(str.lastIndexOf("_")+1,str.length());

retObj.put(“id”, new AMFDataItem(id));

getLogger().info("User id : "+id);

String printip = “”;

getLogger().info(streamList.get(i).getClient().getIp());

for(int a=0;a<streamList.size();a++){

int streamId = streamList.get(a).getClientId();

getLogger().info("Streams “+ id+” streamList: "+streamId);

if(streamId==new Integer(id)) {

String ip = (String) streamList.get(a).getClient().getIp();

printip = ip;

retObj.put(“ip”, new AMFDataItem(ip));

}

}

getLogger().info(“Room:”+str.substring(0,5)+" User ID:"+ id+" ip: "+printip);

}

retArray.add(retObj);

}

if(retArray!=null)

sendResult(client, params, retArray);

}

Here is the Wowza log

getConnectedClinetInfo retrieving info… - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - 4…1807759574 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - 4…1015236877 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - 4…1015236877 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - 4…1807759574 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - MSM COUNTER4 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - 99949_videoStream_1807759574 Streams size: 2 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Room number: 99949 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - User id : 1807759574 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - 192.168.1.68 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Streams 1807759574 streamList: 1807759574 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Streams 1807759574 streamList: 1015236877 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Streams 1807759574 streamList: 1015236877 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Streams 1807759574 streamList: 1807759574 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Room:99949 User ID:1807759574 ip: 192.168.1.68 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - 99949_videoStream_1015236877 Streams size: 2 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Room number: 99949 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - User id : 1015236877 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - 192.168.1.62 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Streams 1015236877 streamList: 1807759574 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Streams 1015236877 streamList: 1015236877 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Streams 1015236877 streamList: 1015236877 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Streams 1015236877 streamList: 1807759574 - - - 77.203 - - - - - - - - - - - - - - - - - - - - - - - - -

2010-02-11 14:37:19 NZDT comment server INFO 200 - Room:99949 User ID:1015236877 ip: 192.168.1.62

Also, I have got another question about H.264. Wowza Media Server would encode the stream when gets it from client side and decode the stream when it pass to a destination. how do we know the server is using H.264?

Since we used red5 server before and just got into Wowza recently. The bandwidth of download or upload a stream is about the same as red5, so I am curious about how the wowza server uses the H264 to compress streams and reduce the bandwidth.

Hi Richard,

Originally, I thought wowza has encoder to encode stream to h264.

Do you have any recommendations of encoder for encoding a web stream to H264?

Hi everyone!

I’m trying to make some sort of statistics for Wowza and need to get client IP address. I’ve successfully used stream.getClient().getIp() method for resolving the address while testing my module with rtmp flash player. But when I tried playing the stream with a rtsp player, the method returned null. Later I’ve figured out that for rtsp sessions I have to use stream.getRTPStream().getOutHost(). What is the method for getting client IP for HTTP Streamer session? stream.getHTTPStreamerSession().getIpAddress()?

If I want to get the client IP for all types of streams/sessuions Wowza supports, are these three methods sufficient?

Exactly what strings does stream.getStreamType() return?

Hi Richard!

I’ve looked through the topics you pointed out, but they don’t satisfy my needs. First of all, onHTTPSessionCreate/Destroy() are called every time a client tries or stops trying to connect to Wowza, which does not definitely mean that the stream will be played. For example, when a client mistypes the name of the stream, the methods are called, but no real streaming occurs. That’s quite a problem for statistics. The same problems are solvable using clientListener for rtmp and actionListener for rtsp, but I can’t find anything similar for http streams. Here’s the code:

package com.wowza.wms.plugin.collection.module;
import com.wowza.wms.amf.*;
import com.wowza.wms.application.*;
import com.wowza.wms.rtp.model.IRTSPActionNotify;
import com.wowza.wms.rtp.model.RTPSession;
import com.wowza.wms.rtsp.RTSPRequestMessage;
import com.wowza.wms.rtsp.RTSPResponseMessages;
import com.wowza.wms.stream.IMediaStream;
import com.wowza.wms.stream.IMediaStreamActionNotify2;
import com.wowza.wms.httpstreamer.model.IHTTPStreamerSession;
import com.wowza.wms.module.*; //these imports for sql
import java.sql.Connection;
import java.util.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ModuleStatistics extends ModuleBase {
//some code here
	public void onStreamCreate(IMediaStream stream) {
		getLogger().info("onStreamCreate by: " + stream.getClientId());
		IMediaStreamActionNotify2 actionNotify = new StreamListener();
		WMSProperties props = stream.getProperties();
		synchronized (props) {
			props.put("streamActionNotifier", actionNotify);
		}
		stream.addClientListener(actionNotify);
	}
	public void onStreamDestroy(IMediaStream stream) {
		getLogger().info("onStreamDestroy by: " + stream.getClientId());
		IMediaStreamActionNotify2 actionNotify = null;
		WMSProperties props = stream.getProperties();
		synchronized (props) {
			actionNotify = (IMediaStreamActionNotify2) stream.getProperties().get("streamActionNotifier");
		}
		if (actionNotify != null) {
			stream.removeClientListener(actionNotify);
			getLogger().info("removeClientListener: " + stream.getSrc());
		}
	}
	public void onHTTPSessionDestroy(IHTTPStreamerSession httpSession) {
//some code here
	}
	public void onRTPSessionCreate(RTPSession rtpSession) {
		IRTSPActionNotify rtspActNot = new rtpSessionListener();
		WMSProperties props = rtpSession.getProperties();
		synchronized (props) {
			props.put("sessionActionListener", rtspActNot);
		}
		rtpSession.addActionListener(rtspActNot);
	}
	public void onRTPSessionDestroy(RTPSession rtpSession) {
		IRTSPActionNotify rtspActNot = null;
		WMSProperties props = rtpSession.getProperties();
		synchronized (props) {
			rtspActNot = (IRTSPActionNotify) rtpSession.getProperties().get("sessionActionListener");
		}
		if (rtspActNot != null) {
			rtpSession.removeActionListener(rtspActNot);
			getLogger().info("removeActionListener");
		}
	}
	
	class rtpSessionListener implements IRTSPActionNotify {
		@Override
		public void onAnnounce(RTPSession arg0, RTSPRequestMessage arg1,
				RTSPResponseMessages arg2) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onDescribe(RTPSession arg0, RTSPRequestMessage arg1,
				RTSPResponseMessages arg2) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onGetParameter(RTPSession arg0, RTSPRequestMessage arg1,
				RTSPResponseMessages arg2) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onOptions(RTPSession arg0, RTSPRequestMessage arg1,
				RTSPResponseMessages arg2) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onPause(RTPSession arg0, RTSPRequestMessage arg1,
				RTSPResponseMessages arg2) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onPlay(RTPSession session, RTSPRequestMessage reqmes,
				RTSPResponseMessages resmes) {
			// TODO Auto-generated method stub
			//some code here
		}
		@Override
		public void onRecord(RTPSession arg0, RTSPRequestMessage arg1,
				RTSPResponseMessages arg2) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onRedirect(RTPSession arg0, RTSPRequestMessage arg1,
				RTSPResponseMessages arg2) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onSetParameter(RTPSession arg0, RTSPRequestMessage arg1,
				RTSPResponseMessages arg2) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onSetup(RTPSession arg0, RTSPRequestMessage arg1,
				RTSPResponseMessages arg2) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onTeardown(RTPSession session, RTSPRequestMessage reqmes, RTSPResponseMessages resmes) {
			//some code here
		}
	}
	class StreamListener implements IMediaStreamActionNotify2 {
		public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) {
			//some code here
		}
		public void onSeek(IMediaStream stream, double location) {
		}
		public void onStop(IMediaStream stream) {
			//some code here
		}
		public void onUnPublish(IMediaStream stream, String streamName,
				boolean isRecord, boolean isAppend) {
		}
		public void onPublish(IMediaStream stream, String streamName,
				boolean isRecord, boolean isAppend) {
		}
		public void onPause(IMediaStream stream, boolean isPause,
				double location) {
		}
		@Override
		public void onMetaData(IMediaStream arg0, AMFPacket arg1) {
			// TODO Auto-generated method stub
		}
		@Override
		public void onPauseRaw(IMediaStream arg0, boolean arg1, double arg2) {
			// TODO Auto-generated method stub
		}
	}
}

Is there anything like that for http streams, with onPlay and onStop methods?