Avatar of belias1
belias1Flag for United States of America

asked on 

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

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
TCP/IPScripting LanguagesNetworking

Avatar of undefined
Last Comment
belias1
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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"?
Avatar of belias1
belias1
Flag of United States of America image

ASKER

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. User generated image
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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.
Avatar of belias1
belias1
Flag of United States of America image

ASKER

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
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of belias1
belias1
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of belias1
belias1
Flag of United States of America image

ASKER

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.
Networking
Networking

Networking is the process of connecting computing devices, peripherals and terminals together through a system that uses wiring, cabling or radio waves that enable their users to communicate, share information and interact over distances. Often associated are issues regarding operating systems, hardware and equipment, cloud and virtual networking, protocols, architecture, storage and management.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo