Android Question Connecting PHP script with socket and asyncstreams does work

Sergio83

Active Member
Licensed User
Longtime User
Hello everyone and Merry Christmas!

So, I wrote a B4A application to capture and display the MJPG stream from an IP camera and everything works fine using the cam url and port.

As I do not want to address my camera by its url, I wrote a php script that makes a redirection to this camera.

I therefore I replaced the url and the port of the camera by those of this PHP script, and there, nothing works or almost:

- the socket connection is ok, but no "newdata" event raises after initializing the asyncstreams and sending the http header get request.

Note that the addressing of this script via a browser works perfectly: I can see the video

If someone can help me, it would be a nice Christmas gift for me!

Thank you in advance for your assistance
 

Sergio83

Active Member
Licensed User
Longtime User
Ok Erel,

Thank you a lot for your fast reply.

I thought it was something about that!

What you propose me is already fonctionnal in my application, I get all the camera parameters (Ip adress, name, camera type, PTZ availability, etc .. etc) at start. My purpose was just to avoid a port forwarding for each camera on my router (12 cameras) and avoid to carry their "IP-like" adresses on internet.

But another functionnality of my application would be to replay the camera records made by my home-made security server. I do that by connecting (no redirection this time ...) to a php script which sends a response header with a "multipart/x-mixed-replace" mime type and then prints shunk by shunk the mjpg recorded file.

This script runs ok when called via a brother, but doesn't work when called by my B4A mjpg decoder: no "newdata" event is raised after socket connection and "asyncstreams" intitialization and connect.

If you have some idea, I'll be happy to try it!

Best rega
rds
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
Hello Erel,

My B4A application is CCTV oriented, so I have mainly two functions:

1 - viewing the ip cam stream in real time. This is working fine when using a direct connection to the ip cam but not when connecting to a php script which redirects to ip cam (please note that this php script is functionnal using a web browser)

2 - viewing recorded video using a php script which reads a previously recorded file ip cam mjpg stream. For that the php script replies with a "multipart/x-mixed-replace" mime type header then by sending the recorded stream shunk by shunk like a real ip cam (please note this php script is functionnal using a web browser).

My servers are OPENWRT based (a linux distro wireless router oriented) with embedded PHP 5, the web server is uhttpd, may be this can help.

My investigations lead me to think that it is probably not a php interpreter issue, but, may be, an issue for uhttpd which is not able to manage the get http headers I send to.

Here after is the code used to send this header:

--------------------------------------------------------------------------------------------
Private Sub Sock_Connected (Successful As Boolean)
If Successful Then
boundary = ""
Astream.Initialize(sock.InputStream, sock.OutputStream, "astream")
Dim sTmp As String = $"GET ${mPath} HTTP/1.1
Host: ${mHost}
Connection: keep-alive

"$
Astream.Write(sTmp.Replace(Chr(10), CRLF).GetBytes("UTF8"))
End If
End Sub

----------------------------------------------------------------------------------------------
Where "mHost" is the IP address without port, and "mPath" the path and parameters to the php script

The result is that no "newdata" event is fired.

Best regards
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…