How do I maintain an open socket to receive TCP strings and generate an HTTP GET from these?

belias1
belias1 used Ask the Experts™
on
I have two devices that I need to establish communication between (IP Camera --> Automation Controller).  I've made some progress, but I've run into a road-block that I'm looking for some assistance with.  Any help would be greatly appreciated.


GENERAL IDEA:

1.  IP Camera - Sends a plain text string to 192.168.2.XXX:XXXX; expects this port (socket?) to remain open indefinitely.  When the port is closed, it takes up to 3 minutes for the camera to recognize this (and reconnect) and during this time no communication is transmitted - a big problem.

                        |
                        |    transmits to
                       V

2.  Automation Controller - Receives commands via HTTP GET interface.  Closes the socket after the GET command is received and really irritates the IP camera.

The Automation Controller can be triggered by opening a browser window and entering:

http://username:password@IP_Address/rest/programs/0071/runThen


WHERE I'M AT SO FAR:

I have changed the text string that the camera sends to:

GET /rest/programs/0071/runThen HTTP/1.1[CRLF]Authorization: Basic xxxxxxxxxx[CRLF][CRLF]

where [CRLF] = carriage return / line feed (i.e. new line)

This works great the first time.  However, after the command is received the Automation Controller responds with a 200 and closes the connection.


WHAT I'M LOOKING FOR:

A method to transmit a text string (i.e. "motion detected") to an Automation Controller that doesn't result in a closed socket connection.  This may be a change in the text string format, or a small program that runs on my server PC, etc.

Actually, I don't really care about the specifics - only that the end result is reliable communication from the IP camera to the Automation Controller.    Open to ideas...


SOME MORE SPECIFICS:

After doing a bit of research on my own (and you'll have to excuse my inexperience here), apparently the camera is expecting the server to be a simple TCP server, as opposed to an HTTP server that closes the connection after each GET request.

The camera is simply sending a plain text string to a port.  In this case, the default string from the camera is "motion detected". As an example, if I send this string to PC-based recording software, it accepts the string with no reply and does not close the connection. I confirmed this with telnet - the port remains open indefinitely on the recording software waiting for additional strings. Apparently, this method is fairly standard in the IP camera industry...



Thanks for the help!


- Brian
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
That doesn't make a whole lot of sense.  'GET' is an HTTP command and I never heard of a "simple TCP server".  If the "Automation Controller" is responding with '200' which means success, then it is acting like a HTTP/web server.

Do you have model numbers or software name for the "Automation Controller"?

Author

Commented:
The Automation Controller is an ISY 99i by Universal Devices.  You are absolutely correct - it is acting as an HTTP/web server exactly as expected (including closing the socket which is causing the issue).

Perhaps I used the wrong terminology for "simple TCP server" - sorry about that.  Maybe it's easier to explain using two test cases:

Test Case #1:  Camera --> Recording Software (not the controller) that it's designed to work with.  See "Recording Software" screenshot.  This software listens on Port 1234 for the string "motion detection".  When something sends this string via TCP, the event is triggered.  Works perfectly every time.  As a test, I opened a telnet session to this port (1234).  When I entered in "motion detection" (I saw echoed characters) and hit enter, the event triggered successfully and the socket did not close (I got no further response from the server).


Test Case #2:  Camera --> Automation Controller.  This is designed to receive an HTTP GET to trigger an event.  As a test, I opened a telnet session to this port now on the Controller.  I entered in the HTTP GET command as posted earlier and the event on the controller triggered correctly.  The controller responded with the appropriate HTML headers and nicely closed the connection.  At this point I'd have an issue with the camera...


Hope this help a little more.  Let me know if I can provide anything else.


Thanks a bunch for the quick response - I really appreciate it. Screenshot of event/port setup for recording software
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
First, you're going about it wrong.  You're the one who is supposed to interface with the web server in order to control the system.  Second, since your camera doesn't appear to be in the short list of networked devices ( http://www.universal-devices.com/mwiki/index.php?title=ISY-99i_Series_INSTEON:Networking:Network_Resources ), you will have to write an interface program that runs on the ISY 99i to receive the data and do something with it.  That capability is not built-in.  You will likely need some of the add-ons that they have.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I appreciate the effort with this, however the problem is not with the Automation Controller.  The Automation Controller already includes a very nice HTTP based interface for external program activation.  All I need to do is send an HTTP GET command to a specific URL on the Automation Controller and my program runs.  This is working fine.

The problem is that the IP camera is expecting to send information through a socket that does not close.  The Automation Controller is an HTTP server, and therefore wants to close the socket after the HTTP GET command is received.

Maybe I should have made my original question much more specific - and my fault for this...  

Here's what I need:

1.  Open a port on a Windows PC and listen for TCP data; socket connections should NOT be closed on this port after data is received; i.e. it is simply monitoring inbound data on this port

2.  When a particular plain text string is received over this port, an HTTP GET command must be issued to a different IP address:port.  It should be expected that this socket will be closed by the HTTP server.

3.  The process must be available to be repeated multiple times.


Thanks again for the effort.


- Brian
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
You still need a program that is listening on the desired port, no matter what system it is on.  That is the way it works.  No listener, no open port.  We answer that same question often here.  After that, the program has to take the action that you want after it receives the data from the camera.
Commented:
I solved this problem with a Python script to monitor the TCP port for activity, and then relay this information to the web server.  Unfortunately, the answer suggested above did not help in this case.

Author

Commented:
I solved this problem with a Python script to monitor the TCP port for activity, and then relay this information to the web server.  Unfortunately, the answer suggested above did not help in this case.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial