TCP Server and Client Example Socket Programs "D7-ON" please

Got the near-real time working but with some ugly hack to the AJAX request. (I did a page reset inside the AJAX). Just clued in to why the AJAX fails and that is; I have to print out a correctly formed HTTP response header. Strangely having a really hard time finding out how that header should look. Any one have any ideas? It should have HTTP and content length and then send the reply. Then AJAX will close.

P.S. I had to eventually give up on serial.println(""); as it caused a ton of Core crashing, eventually thought it should work, got rid of the serial, and D7 lite up immediately.

Found other information here

the link here seems interesting
http://blog.ubidots.com/measure-temperature-and-humidity-with-your-spark-core

and

UPDATE: May 9th.
The response header to a POST request should look something like

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 8

done-now

Very frustrating. I am either getting a good AJAX response but no D7 connection, or I am getting D7 turning on, but AJAX does not finish. Leaning towards my AJAX timer page reset as a bad solution.

I don't think server.println("anything"); works for AJAX, server.write('C'); does seem to work.

So the github site at GitHub - hpssjellis/spark-core-socket-client-or-server: Attempt to test using the spark core or photon as a client or server for fast communication to light D7 LED does work, everything is a bit of a mess. I found code sort of like XMLHttpRequest().abort() which solved the page refresh issue. Still a slight time lag after the call, so really, things are not much better than the non-ajax situation I set up for GET calls.

I will try to clean up the code.