• SEARCH
  • DOWNLOADS
  • MY ACCOUNT
  • Buy (0)
  • CONTACT
  • Free Trial
Wowza Logo
  • PRODUCTS
  • DEVELOPER
  • SOLUTIONS
  • PRICING
  • RESOURCES
  • SUPPORT
  • My Account
  • Buy (0)
  • SEARCH
  • Ask a question
  • Forums
    • Wowza ClearCaster
    • Wowza Streaming Engine
    • Wowza Streaming Cloud
    • Wowza Player
    • Wowza GoCoder SDK
    • Wowza Developer Dojo
    • Topics
    • Questions
    • Articles
    • Users
    • Badges
  • Sign in
  • Community Home /
  • Wowza Developer Dojo /
  • Wowza Streaming Server Java API /
avatar image
Question by Micah Nolte · Oct 16, 2012 at 12:39 PM · wowza streaming server java api

Set Timeout on HTTPUtils.HTTPRequestToByteArray

Hi there. We have a setup where whenever someone begins streaming to Wowza, it checks the stream name with our webserver. This request is set up so that if the webserver is down, Wowza will let them stream.

The problem is that if the webserver handles the request very slowly, the encoder (FMLE) gives up before Wowza gives up trying to connect to the webserver, and FMLE stops trying to connect to Wowza, failing with an error message. I added in a 30 second delay to my webserver to test this.

How can I set a timeout setting on HTTPUtils.HTTPRequestToByteArray?

Here is the code that connects to the webserver:

	public static Boolean requestPublish( String pingParams )
	{
		Boolean streamAllowed = false;
		try
		{
			// Send the request to the website to make sure that the password part of the stream is correct.
			byte[] resp = HTTPUtils.HTTPRequestToByteArray("http://www." + baseDomain + "/webserver/url", "POST", pingParams, null);
			String response = new String(resp, "UTF-8");
			if ( response.indexOf("true") >= 0 ) streamAllowed = true;
		}
		catch(Exception e)
		{
			log.error("HscFunc: Failed to check password.");
			log.error(e.getMessage());
			streamAllowed = true;
		}
		return streamAllowed;
	}


Thanks,

Micah
Comment

People who like this

0 Show 0
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Jason Hilton · Oct 17, 2012 at 02:41 PM

Hi

Granted this isn't perfect either but you're better off trying to get it like this

 
URL myUrl = new URL( url );
    URLConnection conn = myUrl.openConnection();
    conn.setConnectTimeout(2000);
    conn.setReadTimeout(2000);
     
    InputStreamReader isr = new InputStreamReader( conn.getInputStream() );
     
      InputSource is = new InputSource( isr );


From here you should be able to take the input and do what you want with it.

Jason
Comment

People who like this

0 Show 1 · Share
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Micah Nolte · Oct 17, 2012 at 02:19 PM 0
Share
Thanks for the help, this was very useful.

Here's what I ended up with:

	public static Boolean requestPublish( String pingParams )
	{
		Boolean streamAllowed = false;
		try
		{
		    URL url = new URL("http://www." + baseDomain + "/webserver/url");
		    URLConnection conn = url.openConnection();
		    conn.setDoOutput(true);
		    conn.setConnectTimeout(3000);
		    conn.setReadTimeout(3000);
		    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
		    wr.write(pingParams);
		    wr.flush();
		    // Get the response
		    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		    String line;
		    while ((line = rd.readLine()) != null) {
		    	if ( line.indexOf("true") >= 0 ) streamAllowed = true;
		    }
		    wr.close();
		    rd.close();
		}
		catch(Exception e)
		{
			log.error("HscFunc: Failed to check password.");
			log.error(e.getMessage());
			streamAllowed = true;
		}
		return streamAllowed;
	}

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Sample code to use MediaCaster API to start/stop a stream 2 Answers

A question about the IPushPublishRTMPNotify class in the PushPublishing API 1 Answer

StreamPublisher and corrupted video playback 1 Answer

StreamPublisher Module 1 Answer

Howto reject connections while playing streams 9 Answers

Hot Topics
  • AWS Hosting
  • Mobile SDK
  • Deployment Options
  • Load Balancing
  • Content Security
Product Sign-in
  • Wowza Streaming Cloud
  • Wowza Player
Under the Hood
  • Developer Tools
  • Wowza System Status
  • Test Players
  • Developer IDE
Resellers
  • Find a Reseller
  • Reseller Portal
  • Become a Reseller
Company
  • About Us
  • Blog
  • News
  • Events
  • Careers
  • Customers
  • Partners
  • Contact Us
Stay Connected
Get Monthly Newsletter
Select a Language
  • English
    • English
    • Español
    • 日本語
    • 한국어
    • हिन्दी भाषा
    • 中文
    • русский язык

© 2005–2019 Wowza Media Systems, LLC. All rights reserved.   Terms | Privacy | Trademarks | Legal


Enterprise
Social Q&A

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Forums
  • Wowza ClearCaster
  • Wowza Streaming Engine
  • Wowza Streaming Cloud
  • Wowza Player
  • Wowza GoCoder SDK
  • Wowza Developer Dojo
  • Explore
  • Topics
  • Questions
  • Articles
  • Users
  • Badges