We help IT Professionals succeed at work.
Get Started

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

Last Modified: 2012-05-11
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.


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

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:



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.


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


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
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE