# Sample Java class for creating a command line interface to control Wowza Media Server

**URL:** <https://community.wowza.com/t/sample-java-class-for-creating-a-command-line-interface-to-control-wowza-media-server/34950>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [June 21, 2011, 11:49am UTC](https://community.wowza.com/t/sample-java-class-for-creating-a-command-line-interface-to-control-wowza-media-server/34950 "2011-06-21T11:49:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shekar\_KCB](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@shekar\_KCB](https://community.wowza.com/u/shekar_KCB)\
**Post date:** [June 21, 2011, 11:49am UTC](https://community.wowza.com/t/sample-java-class-for-creating-a-command-line-interface-to-control-wowza-media-server/34950/1 "2011-06-21T11:49:32Z")

</div>

My system is Linux, and java is in

```auto
/usr/lib64/jvm/java/bin

```

i copied [this code](https://www.wowza.com/docs/how-to-set-up-a-command-line-interface-to-wowza-api)an pasted to a file called JMXCommandLine.java. Then i run this command

```auto
 javac JMXCommandLine.java 

```

it didn’t gave any errors. It created .class file.

```auto
linux-l6al:/usr/lib64/jvm/java/bin # ls -lrt | tail            
-rwxr-xr-x 1 root root 51619 Apr 13 2010 extcheck            
-rwxr-xr-x 1 root root 51872 Apr 13 2010 apt                 
-rwxr-xr-x 1 root root 51987 Apr 13 2010 appletviewer        
-rwxr-xr-x 1 root root 6347 Apr 13 2010 jcontrol            
-rwxr-xr-x 1 root root 92954 Apr 13 2010 javaws              
-rwxr-xr-x 1 root root 96 Jul 6 2010 HtmlConverter       
lrwxrwxrwx 1 root root 8 Apr 18 19:31 ControlPanel -> jcontrol
-rw-r--r-- 1 root root 18099 Jun 21 11:29 JMXCommandLine.java     
-rw-r--r-- 1 root root 1505 Jun 21 11:29 JMXCommandLine$AppConextName.class
-rw-r--r-- 1 root root 11441 Jun 21 11:29 JMXCommandLine.class              
linux-l6al:/usr/lib64/jvm/java/bin #

```

When i run for usage help it showed me this.

```auto
linux-l6al:/usr/lib64/jvm/java/bin # java -cp . JMXCommandLine $@
Usage:
[command] -[switch [value]...] [command] [params...]
Switches:
  -jmx [jmx-url]
  -user [jmx-username]
  -pass [jmx-password]
Commands:
  getServerVersion
  startVHost [vhost]
  stopVHost [vhost]
  reloadVHostConfig
  startAppInstance [vhost:application/appInstance]
  touchAppInstance [vhost:application/appInstance]
  shutdownAppInstance [vhost:application/appInstance]
  startMediaCasterStream [vhost:application/appInstance] [stream-name] [mediacaster-type]
  stopMediaCasterStream [vhost:application/appInstance] [stream-name]
  resetMediaCasterStream [vhost:application/appInstance] [stream-name]
  getConnectionCounts
  getConnectionCounts [vhost:application/appInstance]
  getConnectionCounts [vhost:application/appInstance] [stream-name]
  getIOOutByteRate
  getIOOutByteRate [vhost:application/appInstance]
  getIOInByteRate
  getIOInByteRate [vhost:application/appInstance]
linux-l6al:/usr/lib64/jvm/java/bin #

```

Now when i am executing with options it gave this error.

```auto
linux-l6al:/usr/lib64/jvm/java/bin # java -cp . JMXCommandLine -user admin -pass password getServerVersion
ERROR: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
        java.net.ConnectException: Connection refused]
linux-l6al:/usr/lib64/jvm/java/bin #
linux-l6al:/usr/lib64/jvm/java/bin #
linux-l6al:/usr/lib64/jvm/java/bin # java -cp . JMXCommandLine getServerVersion
ERROR: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
        java.net.ConnectException: Connection refused]
linux-l6al:/usr/lib64/jvm/java/bin #

```

As i am not of programing background, What this errors are corresponds to ?

All i need is a way to start and stop the streams using command line tool…

And if my URL is

```auto
 rtmp://192.168.1.123:1935/testlive/testlive.stream

```

, whet should be the correct sequence to start stop stream using this app.

Thanks,

Shekar

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [June 21, 2011, 2:51pm UTC](https://community.wowza.com/t/sample-java-class-for-creating-a-command-line-interface-to-control-wowza-media-server/34950/2 "2011-06-21T14:51:23Z")

</div>

Shekar,

Make sure Wowza is running.

Make sure /conf/Server.xml /JMXRemoteConfiguration /Enable is set to “true”

Make sure you /conf/jmxremote.access and jmxremote.password have user “admin” and password “admin” with readwrite privileges.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [June 27, 2011, 2:42pm UTC](https://community.wowza.com/t/sample-java-class-for-creating-a-command-line-interface-to-control-wowza-media-server/34950/3 "2011-06-27T14:42:23Z")

</div>

The example in the guide is:

```auto
to start stream:
jmxcl [jmx-connection-switches] touchAppInstance live
jmxcl [jmx-connection-switches] startMediaCasterStream live myStream.sdp rtp

```

Not sure where you are going after that.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [June 28, 2011, 12:34pm UTC](https://community.wowza.com/t/sample-java-class-for-creating-a-command-line-interface-to-control-wowza-media-server/34950/4 "2011-06-28T12:34:44Z")

</div>

Shekar,

I haven’t used this method very much, but I think the way to discover the commands and parameters is look at JConsole and find the Operations screens.

[https://www.wowza.com/docs/quick-start-guides](https://www.wowza.com/docs/quick-start-guides)

Richard

---

<div class="post-metadata">

**Author:** ![shekar\_KCB](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@shekar\_KCB](https://community.wowza.com/u/shekar_KCB)\
**Post date:** [June 27, 2011, 4:06pm UTC](https://community.wowza.com/t/sample-java-class-for-creating-a-command-line-interface-to-control-wowza-media-server/34950/5 "2011-06-27T16:06:28Z")

</div>

Thanks for the reply Richard. Glad now i can make this working ( getServerViersion method is working it is showing me

```auto
Wowza Media Server 2 Subscription 2.2.4 build27452

```

hope its latest… )

Now how do i start/stop the stream? when i tried i get this error.

```auto
linux-l6al:/etc/alternatives/java_sdk/bin # java -cp . JMXCommandLine -user admin -pass admin startMediaCasterStream testlive testlive.stream rtp
startMediaCasterStream testlive testlive.stream rtp
ERROR: doInvoke: javax.management.InstanceNotFoundException: WowzaMediaServerPro:vHosts=VHosts,vHostName=_defaultVHost_,applications=Applications,applicationName=testlive,applicationInstances=ApplicationInstances,applicationInstanceName=_definst_,name=ApplicationInstance
linux-l6al:/etc/alternatives/java_sdk/bin #

```

But i can play the url

```auto
rtmp://localhost:1935/testlive/testlive.stream

```

Any idea?

Actually i wanted to use “liverepeater-record” method in origin (for vod kind of streaming), and record the particular incoming stream every hrs, and the use the smil to stream them separately… which method is suitable ? is it

```auto
startAppInstance OR startMediaCasterStream ? 

```

as everything stream started/stoped it creates an mp4 file …

Thanks.

---

<div class="post-metadata">

**Author:** ![shekar\_KCB](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@shekar\_KCB](https://community.wowza.com/u/shekar_KCB)\
**Post date:** [June 28, 2011, 11:17am UTC](https://community.wowza.com/t/sample-java-class-for-creating-a-command-line-interface-to-control-wowza-media-server/34950/6 "2011-06-28T11:17:51Z")

</div>

How do i find out which is the correct format?

Can the guy who developed reply for this?

Thanks,

Shekar
